¿Cómo obtener solo la parte date de getdate ()? [duplicar]
Esta pregunta ya tiene una respuesta aquí:
Tengo una tabla SQL que tiene un campo creationDate.
Tengo getdate()
en la fórmula de especificación de la columna calculada.
Me gustaría saber cómo obtener solo la porción de fecha, es decir, '2012-08-24' en lugar de '2012-08-24 10:45:17.740'.
48
Author: Jon Schneider, 2012-08-24
5 answers
Si está utilizando SQL Server 2008 o posterior
select convert(date, getdate())
De lo contrario
select convert(varchar(10), getdate(),120)
79
Author: podiluska,
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
2012-08-24 08:55:43
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
2012-08-24 08:55:43
Prueba esto:
select convert (date ,getdate())
O
select CAST (getdate() as DATE)
O
select convert(varchar(10), getdate(),121)
7
Author: Joe G Joseph,
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
2012-08-24 08:55:38
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
2012-08-24 08:55:38
Prueba esto:
SELECT CONVERT(date, GETDATE())
3
Author: András Ottó,
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
2012-08-24 08:48:59
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
2012-08-24 08:48:59
SELECT CONVERT(date, GETDATE())
3
Author: John Woo,
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
2012-08-24 08:49:50
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
2012-08-24 08:49:50
SELECT CAST(FLOOR(CAST(GETDATE() AS float)) as datetime)
O
SELECT CONVERT(datetime,FLOOR(CONVERT(float,GETDATE())))
3
Author: Akkarapon S.,
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-05-22 00:14:47
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-05-22 00:14:47