| Author |
Topic |
|
aoriju
Posting Yak Master
156 Posts |
Posted - 2008-07-24 : 04:15:01
|
| how to set todays maximum timestamp to getdate() functioneg:getdate()Ans :2008-07-24 13:16:48.727 ----Currenti want to get 2008-07-24 23:59:59.727 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 04:16:15
|
quote: Originally posted by aoriju how to set todays maximum timestamp to getdate() functioneg:getdate()Ans :2008-07-24 13:02:48.727i want to get 2008-07-24 24:59:59.727
are you sure that's what you want?Em |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 04:17:16
|
| but still.... why milliseconds of .727 ???Em |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-24 : 04:21:14
|
[code]SELECT DATEADD(DAY, DATEDIFF(DAY, '19000101', getdate()), '19000101 23:59:59.997'), DATEADD(DAY, DATEDIFF(DAY, '19000101', getdate()), '19000102')[/code]If you are going to compare the date with a column in a table like thisselect * from table1 where column1 <= {above first result}you are better off with using the second result like thisselect * from table1 where column1 < {above second result}That way, you are sure that all records for today are fetched, and your code will work on SQL Server 2008 as well.Pre SQL Server 2008 has a time resolution of 3/1000th of a second. That's why 997 milliseconds are the last time for a day.That is going to change in SQL Server 2008. There you can have a resolution of a microsecond Yes, then the time part will end with .999999So use the second alternative above to compare dates. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 04:29:31
|
| in 2008 i think the .999999 is only relevant to the seperate TIME datatype and DATETIME2. DATETIME is still acurate to .997Em |
 |
|
|
aoriju
Posting Yak Master
156 Posts |
Posted - 2008-07-24 : 04:30:47
|
Not worry about millisecond ....i want last time of today in getdate function()quote: Originally posted by Peso
SELECT DATEADD(DAY, DATEDIFF(DAY, '19000101', getdate()), '19000101 23:59:59.997'), DATEADD(DAY, DATEDIFF(DAY, '19000101', getdate()), '19000102') If you are going to compare the date with a column in a table like thisselect * from table1 where column1 <= {above first result}you are better off with using the second result like thisselect * from table1 where column1 < {above second result}That way, you are sure that all records for today are fetched, and your code will work on SQL Server 2008 as well.Pre SQL Server 2008 has a time resolution of 3/1000th of a second. That's why 997 milliseconds are the last time for a day.That is going to change in SQL Server 2008. There you can have a resolution of a microsecond Yes, then the time part will end with .999999So use the second alternative above to compare dates. E 12°55'05.25"N 56°04'39.16"
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-24 : 04:45:59
|
quote: Originally posted by aoriju Not worry about millisecond ....i want last time of today in getdate function()quote: Originally posted by Peso
SELECT DATEADD(DAY, DATEDIFF(DAY, '19000101', getdate()), '19000101 23:59:59.997'), DATEADD(DAY, DATEDIFF(DAY, '19000101', getdate()), '19000102') If you are going to compare the date with a column in a table like thisselect * from table1 where column1 <= {above first result}you are better off with using the second result like thisselect * from table1 where column1 < {above second result}That way, you are sure that all records for today are fetched, and your code will work on SQL Server 2008 as well.Pre SQL Server 2008 has a time resolution of 3/1000th of a second. That's why 997 milliseconds are the last time for a day.That is going to change in SQL Server 2008. There you can have a resolution of a microsecond Yes, then the time part will end with .999999So use the second alternative above to compare dates. E 12°55'05.25"N 56°04'39.16"
Peso explained well on how to use it in a queryWhy do you want to know the last time of the day?MadhivananFailing to plan is Planning to fail |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2008-07-24 : 09:38:52
|
| Jeez, people. Maybe he has a legit reason for wanting this:select dateadd(millisecond, -2, dateadd(day, datediff(day, 0, getdate()), 0))e4 d5 xd5 Nf6 |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-07-24 : 09:49:14
|
quote: Originally posted by blindman Jeez, people. Maybe he has a legit reason for wanting this:select dateadd(millisecond, -2, dateadd(day, datediff(day, 0, getdate()), 0))e4 d5 xd5 Nf6
That returns the last time for yesterday.select TodaysLastTime = dateadd(day,datediff(day,0,getdate()),'23:59:59.997')Results:TodaysLastTime ------------------------------------------------------ 2008-07-24 23:59:59.997(1 row(s) affected) CODO ERGO SUM |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2008-07-24 : 10:43:07
|
| So nit-picky. I was only off by one day, which is pretty dang close considering that the Earth is billions of years old, don'tcha think?What I meant to post was this:select dateadd(millisecond, -2, dateadd(day, datediff(day, 1, getdate()), 0))e4 d5 xd5 Nf6 |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 10:46:34
|
don't be ridiculous! 0 is 19000101 so how can it possible be billions of years old!? Em |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2008-07-24 : 11:49:26
|
| That is all the proof I needed. Thanks.e4 d5 xd5 Nf6 |
 |
|
|
|