Cómo seleccionar fecha sin hora en SQL


Cuando selecciono date en SQL se devuelve como 2011-02-25 21:17:33.933. Pero solo necesito la parte de la Fecha, que es 2011-02-25. ¿Cómo puedo hacer esto?

Author: Yi Jiang, 2011-02-26

16 answers

Supongo que quiere una cadena

select convert(varchar(10), '2011-02-25 21:17:33.933', 120)
 125
Author: bernd_k,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-26 07:57:46

Para SQL Server 2008:

Convert(date, getdate())  

Por favor refiérase a https://docs.microsoft.com/en-us/sql/t-sql/functions/getdate-transact-sql

 395
Author: Prad9,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-26 17:41:46

El más rápido es datediff, por ejemplo,

select dateadd(d, datediff(d,0, [datecolumn]), 0), other..
from tbl

Pero si solo necesita usar el valor, puede omitir el dateadd, por ejemplo,

select ...
WHERE somedate <= datediff(d, 0, getdate())

Donde la expresión datediff(d, 0, getdate()) es suficiente para devolver la fecha de hoy sin porción de hora.

 47
Author: RichardTheKiwi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-24 19:40:23

Use CAST(GETDATE() como date) que funcionó para mí, simple.

 30
Author: Anna-leny,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-27 21:31:22
 20
Author: Orbit,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-21 08:48:22

Puedes usar así

SELECT Convert(varchar(10), GETDATE(),120) 
 11
Author: A.Goutam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-16 12:22:41

Para la versión anterior de 2008 :

SELECT DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)

 10
Author: DomCha,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-09 14:06:55

Es un poco tarde, pero use la función ODBC "curdate" (angle brackes 'fn' es la secuencia de escape de la función ODBC).

SELECT {fn curdate()} 

Salida: 2013-02-01

 2
Author: Stefan Steiger,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-21 08:49:11

Puedes probar este también.

SELECT CONVERT(DATE, GETDATE(), 120)
 2
Author: Ram Pratap,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-24 18:01:45

Conviértalo de nuevo a datetime después de convertir a date para mantener el mismo datatime si es necesario

select Convert(datetime, Convert(date, getdate())  )
 1
Author: RollRoll,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-15 21:48:33

En PLSQL puede usar

to_char(SYSDATE,'dd/mm/yyyy')
 0
Author: Morterox,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-30 18:25:21

Primero Convierta la fecha en flotante (que muestra el numérico), luego ROUND el numérico a 0 puntos decimales, luego conviértalo en datetime.

convert(datetime,round(convert(float,orderdate,101),0) ,101)
 0
Author: user4162468,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-20 16:18:16

Si desea devolver una fecha, escriba solo una fecha, use

CONVERT(date, SYSDATETIME())

O

SELECT CONVERT(date,SYSDATETIME()) 

O

DECLARE @DateOnly Datetime
SET @DateOnly=CONVERT(date,SYSDATETIME())
 0
Author: TMP ByKIS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-26 19:17:21

El uso es simple:

convert(date, Btch_Time)

Ejemplo a continuación:

Cuadro:

Efft_d       Loan_I  Loan_Purp_Type_C   Orig_LTV    Curr_LTV    Schd_LTV    Un_drwn_Bal_a      Btch_Time            Strm_I  Btch_Ins_I
2014-05-31  200312500   HL03             NULL         1.0000    1.0000         1.0000      2014-06-17 11:10:57.330  1005    24851e0a-53983699-14b4-69109


Select * from helios.dbo.CBA_SRD_Loan where Loan_I in ('200312500') and convert(date, Btch_Time) = '2014-06-17'
 0
Author: Arvind Kumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-26 08:21:23

Prueba esto.

SELECT DATEADD(DD, 0, DATEDIFF(DD, 0, GETDATE()))
 0
Author: Ram Pratap,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-24 17:58:29

SELECCIONE la fecha('2011-02-25 21:17:33.933') como fecha nos dará 2011-02-25.

Funcionó para mí. Espero que funcione.

 0
Author: Mazhar Ghulam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-07 06:02:06