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 2005 Forums
 Transact-SQL (2005)
 rounding 100th second to 10th second
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

slihp
Yak Posting Veteran

60 Posts

Posted - 04/03/2013 :  11:38:52  Show Profile  Reply with Quote
I have a datetime field in a table

2008-10-21 19:59:14.817

i want to round these entries to nearest 10ths of seconds so

2008-10-21 19:59:14.817 would become 2008-10-21 19:59:14.810


James K
Flowing Fount of Yak Knowledge

3712 Posts

Posted - 04/03/2013 :  12:41:48  Show Profile  Reply with Quote
Based on your example it looks like you want to TRUNCATE (rather than round) to the nearest 100th of a second (rather than 10th of a second)
DATEADD(ms,-datepart(ms,YourDateTimeColumn)%10,YourDateTimeColumn)
You have to be using datetime and not smalldatetime, of course.
Go to Top of Page

slihp
Yak Posting Veteran

60 Posts

Posted - 04/04/2013 :  04:13:57  Show Profile  Reply with Quote
Thanks James

yes i want to remove the ms, and your solution works. out of interest can you round up or down based on the ms?
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 04/04/2013 :  04:52:42  Show Profile  Reply with Quote
Refer this link
http://stackoverflow.com/questions/13368868/sql-server-round-a-datetime-to-the-nearest-5-seconds
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.06 seconds. Powered By: Snitz Forums 2000