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
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
What is the baseline for the integers?
ASKER
This number is the number of SECONDS since 1970, 01, 01
It is stored into the database as an int (4)
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)
then 1077642495 is the date:
1077642495 - 1077558217 + cast('01/01/2004' as datetime)
ASKER
Lets say the field name is
mydate
Criteria would be
mydate-1075400710 + Cast('01/29/2004' as datetime)
mydate
Criteria would be
mydate-1075400710 + Cast('01/29/2004' as datetime)
SELECT DATEADD(SECOND, yourIntValue, '1970-01-01')
e.g. print dateadd(ss, 1077641785, '01/01/1970')
ASKER
How do I implement THIS FORMULA INTO SQL SERVER
MyFieldIntegerValue/86400+ DATE(1970, 1,1)
MyFieldIntegerValue/86400+
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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?