June 15, 2010 at 4:47 am
This might be really obvious but I cannot for the life of me figure out how to get a datetime value with the minutes & seconds set to zero.
ie if I have a time of '2010-04-04 14:15:02'
I want '2010-04-04 14:00:00'
so I'm looking to round my time down to the start of the hour given - can anyone help please I'm sure I'm missing something simple!
Thanks
June 15, 2010 at 4:50 am
SELECT dateadd(hour, datepart(hour,GETDATE()),CAST(convert(varchar(20),getdate(),112) as datetime))
June 15, 2010 at 4:52 am
Good try but that sets the whole time part to zeros.
June 15, 2010 at 4:53 am
Sorry, I have edited the previous post as well:
SELECT dateadd(hour, datepart(hour,GETDATE()),CAST(convert(varchar(20),getdate(),112) as datetime))
June 15, 2010 at 4:56 am
Spot on, thank you for helping.
June 15, 2010 at 11:56 am
June 15, 2010 at 12:33 pm
Much appreciated
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy