Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Date time manipulation

Author  Topic 

stathis30_2000
Starting Member

23 Posts

Posted - 2007-08-28 : 06:15:22
Hi all,

How can I set minutes and seconds to zero in datetime records?
I need to keep only the day part and the hours.

Thanks

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2007-08-28 : 06:27:11
Oops - I just re-read your post!
For the current datetime:
SELECT DATEADD(hour, DATEDIFF(hour, 0, GETDATE()), 0)


Mark
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-08-28 : 06:33:25
This will reset the minutes


declare @date datetime
set @date = getdate()

SELECT DATEADD(minute,DATEdiff(minute,0,@date),0)
Jim
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-08-28 : 06:52:53
Oops! I thought you wanted to keep the minutes!
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-08-28 : 11:17:08
You might find this helpful:

http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx
(Essential SQL Server Date, Time, and DateTime functions)

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -