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)
 rounding 100th second to 10th second

Author  Topic 

slihp
Yak Posting Veteran

61 Posts

Posted - 2013-04-03 : 11:38:52
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-03 : 12:41:48
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

61 Posts

Posted - 2013-04-04 : 04:13:57
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-04 : 04:52:42
Refer this link
http://stackoverflow.com/questions/13368868/sql-server-round-a-datetime-to-the-nearest-5-seconds
Go to Top of Page
   

- Advertisement -