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 |
|
ashish908
Starting Member
18 Posts |
Posted - 2005-05-12 : 07:34:30
|
| i have a table which has a datetime fieldthe tables get populated with rows from an external data source every 15 minutes so the datetime values should be '11/May/05 01:00:00", "11/May/05 01:15:00", '11/May/05 01:30:00", "11/May/05 01:45:00", '11/May/05 02:00:00", "11/May/05 02:15:00", '11/May/05 03:00:00", "11/May/05 03:15:00" and so onBut the external data source pushes data which is not that exacte.g. the values i get is somewhat like this'11/May/05 01:00:00", "11/May/05 01:14:20", '11/May/05 01:31:10", "11/May/05 01:45:40", '11/May/05 02:00:19", "11/May/05 02:14:00", '11/May/05 03:01:00", "11/May/05 03:14:40" and so onhow can i use these above values to generate values like '11/May/05 01:00:00", "11/May/05 01:15:00", '11/May/05 01:30:00", "11/May/05 01:45:00", '11/May/05 02:00:00", "11/May/05 02:15:00", '11/May/05 03:00:00", "11/May/05 03:15:00" in a sql query (ie the values should be rounded off to the nearest 15th minute)i am using sql server 2000 database.Thanks in advance. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-05-12 : 07:45:09
|
| In other words, you want to round a datetime value to the nearest 15-minute interval? |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-05-12 : 07:52:01
|
| SELECt DateAdd(minute, round(DateDiff(minute, 0, dateCol)/15.0, 0)*15, 0) FROM myTable |
 |
|
|
ashish908
Starting Member
18 Posts |
Posted - 2005-05-12 : 12:17:09
|
| thanks a lot, this works |
 |
|
|
|
|
|
|
|