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.
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.817i 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. |
|
|
slihp
Yak Posting Veteran
61 Posts |
Posted - 2013-04-04 : 04:13:57
|
Thanks Jamesyes i want to remove the ms, and your solution works. out of interest can you round up or down based on the ms? |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-04 : 04:52:42
|
Refer this linkhttp://stackoverflow.com/questions/13368868/sql-server-round-a-datetime-to-the-nearest-5-seconds |
|
|
|
|
|