| Author |
Topic |
|
crownclit
Starting Member
20 Posts |
Posted - 2010-10-13 : 18:46:59
|
| Hi I am not really sure how to convert following to usable date or time format.Could you guys help?This data is coming from cisco call centre sql database.dnCallStartTime dnCallEstabTime dnCallStopTime1286402877 1286402881 1286402975 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
crownclit
Starting Member
20 Posts |
Posted - 2010-10-13 : 19:38:47
|
| Thank you tkizer for replyYour Function is working great I can see date\time properly the only problem is that function returns same value [1970-01-15 21:20:02.000] no matter which value of those three listed above I use. Another thing is that my call centre does not receive any call after business hours. This is after 6pm. But this may be a separate issue. |
 |
|
|
crownclit
Starting Member
20 Posts |
Posted - 2010-10-13 : 19:43:19
|
| tkizerconverter works perffect, from 1286402877 value i'm getting [Thu Oct 7 09:07:57 UTC+1100 2010]i need to do same conversion in SQL |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
crownclit
Starting Member
20 Posts |
Posted - 2010-10-13 : 21:04:55
|
| thank you tkizerthis works fine |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-10-14 : 09:46:45
|
quote: Originally posted by tkizer So Epoch time is number of seconds since 1970, and Java time (what my udf is converting in that link) is number of milliseconds since 1970.Why can't people just use good old dates and times? What is the point of using 1970 as a base date? I just don't get it. It's rhetorical, I realize you don't have the answer.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
If you are going to store seconds after 2038-01-19 03:14:07, you will need to revise the logic to use bigint, because an 32 bit integer will overflow.select *, DT = case when UNIXTime between -6847804800 and 253402300799 then dateadd(ss,UNIXTime%86400,(UNIXTime/86400)+25567) else null endfrom ( -- Test Data select UNIXTime = convert(bigint,-6847804800-1) union all select UNIXTime = convert(bigint,-6847804800) union all select UNIXTime = convert(bigint,2147483647) union all select UNIXTime = convert(bigint,6147483647) union all select UNIXTime = convert(bigint,253402300799) union all select UNIXTime = convert(bigint,253402300799+1) ) a Results:UNIXTime DT-------------------- ----------------------- -6847804801 NULL -6847804800 1753-01-01 00:00:00.000 2147483647 2038-01-19 03:14:07.000 6147483647 2164-10-21 10:20:47.000 253402300799 9999-12-31 23:59:59.000 253402300800 NULL(6 row(s) affected) CODO ERGO SUM |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-10-14 : 15:33:48
|
I understand, I just wanted to post code to handle more general cases where it does matter. The code itself really isn't that much more complex and probably executes about as fast.Here is the code to handle conversion of milliseconds since 1970-01-01 to DATETIME.select *, DT = case when JavaTime between -6847804800001 and 253402300799998 then dateadd(ms,JavaTime%86400000,(JavaTime/86400000)+25567) else null endfrom ( -- Test Data select JavaTime = convert(bigint,-6847804800001-1) union all select JavaTime = convert(bigint,-6847804800001) union all select JavaTime = convert(bigint,1202147483647) union all select JavaTime = convert(bigint,6202147483697) union all select JavaTime = convert(bigint,253402300799998) union all select JavaTime = convert(bigint,253402300799998+1) ) a Results:JavaTime DT-------------------- ------------------------ -6847804800002 NULL -6847804800001 1753-01-01 00:00:00.000 1202147483647 2008-02-04 17:51:23.647 6202147483697 2166-07-16 02:44:43.697 253402300799998 9999-12-31 23:59:59.997 253402300799999 NULL(6 row(s) affected) CODO ERGO SUM |
 |
|
|
|