SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Round down seconds from time
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kev8279
Starting Member

United Kingdom
3 Posts

Posted - 05/25/2012 :  11:12:10  Show Profile  Reply with Quote
Hi, I have a table which has a date and time in like this 11:01:39.01234

What I would like to do is round this down to 11:01, regardless of seconds. I have tried a cast to smalldate time however when the seconds are above 30 it rounds up. Can someone help?

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/25/2012 :  11:52:04  Show Profile  Reply with Quote

declare	@dt datetime2	= '2012-05-26 11:01:39.01234'

select	convert(datetime2, convert(varchar(10), @dt, 121) + ' ' + convert(varchar(5), @dt, 108))



KH
Time is always against us

Go to Top of Page

robvolk
Most Valuable Yak

USA
15559 Posts

Posted - 05/25/2012 :  12:00:06  Show Profile  Visit robvolk's Homepage  Reply with Quote
An alternative:
declare @dt datetime2 = '2012-05-26 11:01:39.01234'
SELECT DATEADD(minute,DATEDIFF(minute,0,@dt),0)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000