Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql server current hour 1

Status
Not open for further replies.

jmk418

MIS
May 24, 2004
99
US
This seems pretty basic and I am sure there is a simple way to do this but it is escaping me. What I want is date time with just the current date and hour.
For example at 7:49 today I would like to return 1/26/2009 07:00:00.000 and at 8:15 1/26/2009 08:00:00.000.
I know I can use dateadd and datepart but this will be in a case statement so I would like to keep it as clean as possible.

Thank for your help in advance

Jeremy
 
Take a look at this:

[tt][blue]Select DateAdd(Hour, DateDiff(Hour, 0, GetDate()), 0)[/blue][/tt]

To explain... DateDiff returns an integer, so:

DateDiff(Hour, 0, GetDate())

Returns a whole number of hours that have elapsed since Jan 1, 1900 12:00:00. We then add that whole number of hours back to Jan 1, 1900, which effectively removes the minute and seconds.

Make sense?


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
perfect
exactly what i was looking for
thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top