Get The Hour from date field

  • Hi everyone - I am trying to get the HOUR out of a datefield (2010-03-22 08:24:18.510) in the query of a report that I'm building. I need it so I can group off of it in the layout.

    Is there an easy of doing that? As always, your help is greatly appreciated!

  • Depending on how you want to group....

    1. if you want to group all of the 5 o'clocks for an entire timespan together then use:

    SELECT DATEPART(hh,'3/23/2010 3:00 PM')

    2. if you want to group by the hour, and one day's 5 o'clock is not to be group with another days', then group by calculating the difference in hours since a static date value .... :

    SELECT DATEDIFF(hh,'1/1/1970','3/23/2010 3:00 PM')

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Thank you for the direction!

    I realize that I left a piece of the puzzle out (sorry) but it worked perfectly! Thank you.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply