Link to home
Start Free TrialLog in
Avatar of luckyinc
luckyinc

asked on

Convert UTC Date to MM/DD/YYYY HH MM SS

I currently have integer values in the database examples:

1077558217
1077642495
1077641785

That need to be converted to logical date and time.  
Any suggested functions for SQL Server 2000 or SQL Server 7?

Thanks
LuckyInc
Avatar of millsoft
millsoft

What is the baseline for the integers?
Avatar of luckyinc

ASKER

This number is the number of SECONDS since 1970, 01, 01

It is stored into the database as an int (4)
If you know that 1077558217 is for ex: 01/01/2004
then 1077642495 is the date:
1077642495 - 1077558217 + cast('01/01/2004' as datetime)
Lets say the field name is

mydate

Criteria would be
mydate-1075400710 + Cast('01/29/2004' as datetime)
Avatar of Scott Pletcher
SELECT DATEADD(SECOND, yourIntValue, '1970-01-01')
e.g. print dateadd(ss, 1077641785, '01/01/1970')
How do I implement THIS FORMULA INTO SQL SERVER

MyFieldIntegerValue/86400+DATE(1970,1,1)
That will just give you whole days.  If that's what you want, you can do this:


SELECT DATEADD(DAY, yourIntValue / 86400, '1970-01-01')


Note, then, that the time on the final result will always be midnight, because "/" will drop any remainder.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is not correct.  
If you test with real int representing UTC, such as 1104178047, the above function will report 2004-12-27, but the correct answer is 2005-03-02.  I will repost quesiton.
I noticed that after I accepted the answer...where are you reposting the question?
db/mssql
Repost is Question Title: UTC int Convert to standard DateTime how?