0

I made a SQL Statement and I want to use the date but without the time.

My Select is:

SELECT DATEPART(dw, [Order].PerformDate)

And my Group by is:

GROUP BY [Order].PerformDate

Now how can I ignore the time?

japzdivino
  • 1,736
  • 3
  • 17
  • 25
Magic Mike
  • 25
  • 6

4 Answers4

2

You can use CONVERT function of SQL

select datepart(dw, CONVERT(DATE,[Order].PerformDate)) 
GROUP BY CONVERT(DATE,[Order].PerformDate)
japzdivino
  • 1,736
  • 3
  • 17
  • 25
1

Cast datetime value to date:

select cast(`Order`.PerformDate as date) as PerformDate
Abhishek Ginani
  • 4,511
  • 4
  • 23
  • 35
1

GROUP BY says "I want one result row per ____". In your case one row per PerformDate. If PerformDate is a datetime, but you only want to have one result row per date without time, then you must extract the date part:

group by cast(performdate as date)

You also want to display the weekday with datepart(dw, performdate) but this is no longer possible, because PerformDate is no longer available. Only its date part is. So:

select datepart(dw, cast(performdate as date))
from ...
group by cast(performdate as date);
Thorsten Kettner
  • 89,309
  • 7
  • 49
  • 73
0

Another one method:

select date_format(`order`.PerformDate, '%Y%m%d')
...
group by 1