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 |
|
sqlyukon
Starting Member
8 Posts |
Posted - 2006-06-27 : 14:56:26
|
| Date Conversion using UTC --This Works using Seconds--Be aware that 32-bit signed integer overflows on dates past January 2038.--Original UTC Time as DateTime for comparison after restoreDeclare @OrigUTCTime DateTimeSelect @OrigUTCTime = GetUTCDate()Select @OrigUTCTime as 'Original UTC DateTime'--Original UTC Time in SecondsDeclare @UTCTimeinSeconds intSelect @UTCTimeinSeconds = DateDiff(ss,{ ts '1970-01-01 00:00:00' }, GETUTCDATE())Select @UTCTimeinSeconds as 'Original UTCTime in Seconds'--Restored UTC Time in Seconds to UTC DateTimeSelect DateAdd(ss, @UTCTimeinSeconds, { ts '1970-01-01 00:00:00' }) as 'Restored UTCTime from Seconds' --Milliseconds instead of seconds doesn't work--Original UTC Time as DateTimeDeclare @OrigUTCTime DateTimeSelect @OrigUTCTime = GetUTCDate()Select @OrigUTCTime as 'Original UTC DateTime'--Original UTC Time in MilliSecondsDeclare @UTCTimeinMilliSeconds NumericSelect @UTCTimeinMilliSeconds = DateDiff(ms,{ ts '1970-01-01 00:00:00' }, GETUTCDATE())Select @UTCTimeinMilliSeconds as 'Original UTCTime in MilliSeconds'--Restored UTC Time in MilliSeconds to UTC DateTimeSelect DateAdd(ms, @UTCTimeinMilliSeconds, { ts '1970-01-01 00:00:00' }) as 'Restored UTCTime from MilliSeconds' My Assumption is its exceeding the limit for the output.Problem is even the first batch of queries will fail once we reach date Jan 2038.Does anyone have a solution ?Thanks. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-06-27 : 16:00:11
|
| Try to calculate milliseconds of today and add that to the number of seconds elapsed since 1970-01-01 multiplied with 1000.Peter LarssonHelsingborg, Sweden |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-06-27 : 16:50:29
|
| What exactly are you trying to do? It looks like you are trying to convert the UTC datetime to UNIX time.If that is what you are trying to do, you should look at this topic:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=66858CODO ERGO SUM |
 |
|
|
|
|
|