Reputation: 629
I have a query with a column received
and the value 2014-02-13 19:34:00
. I fetch the date alone using DATE(received)
and value is 2014-02-13
In MySQL I use the following query:
SELECT DATE(received) AS Mydate, status
FROM Notification
WHERE project = 'proj001'
GROUP BY Mydate
ORDER BY received;
How to generate same value in SQL Server?
Upvotes: 1
Views: 80
Reputation: 93734
Use cast
or convert
in SQL Server. Cast
is ANSI standard. Convert
is SqlServer specific
select cast(received as date),status FROM Notification -- or convert(date,received)
WHERE project='proj001'
GROUP BY cast(received as date),status
ORDER BY cast(received as date);
Upvotes: 4
Reputation: 24
If you are using SQL Server 2008 and higher then
SELECT CONVERT(date, '2014-02-13 19:34:00')
if you are using an older version then
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, '2014-02-13 19:34:00'))
Upvotes: 0