BarrettJ
BarrettJ

Reputation: 3431

Sql by hour starting at noon

I'm currently using a select statement with one column as DATEPART(hh, CallTime) AS Hour and then doing:

GROUP BY DATEPART(hh, CallTime) 
ORDER BY Hour

This displays the hours starting at midnight and going through midnight - how would I go about having this go from noon to noon? Thanks!

Upvotes: 2

Views: 580

Answers (1)

DVK
DVK

Reputation: 129403

CASE WHEN (DATEPART(hh, CallTime) >=12) THEN DATEPART(hh, CallTime) - 12 ELSE DATEPART(hh, CallTime)+12 END AS hour_since_noon should do it if I understood your question correctly.

You may want to have 2 separate fields, your original one to actually display and this one to order

Upvotes: 3

Related Questions