Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to part a datetime value and build it together removing minutes, seconds and so on. I want the values to be hourly.

Usually this works on a SQL Server 2012 machine:

DATETIME2FROMPARTS( DATEPART(year, datum), DATEPART(month, datum), DATEPART(day, datum), DATEPART(hour, datum), 0, 0, 0, 0) as dtHour

But unfortunately in SQL Server 2008 it does not! Which function do I need, to fulfill the same job?

I also looked up this reference: Date&Time functions but this were all only SQL Server 2012 compliant.

share|improve this question
The link you reference can display other versions of SQL Server, for instance this is for 2008: – Max Vernon Nov 29 '13 at 20:08
up vote 5 down vote accepted

You can make it a bit shorter.

dateadd(hour, datediff(hour, 0, datum), 0)

This calculates the number of hours between 1900-01-01 00:00:00.000 and datum and adds that value to 1900-01-01 00:00:00.000.

share|improve this answer
nice : ) thank you! ps: i tried to upvote, but unfortunately SO doesnt allow me to upvote, because i dont have 15 rep. points – Erdinc Ay Nov 29 '13 at 12:18
You now have more than enough rep! – Max Vernon Nov 29 '13 at 20:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.