Solved

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

Posted on 2004-04-08
13
803 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:luckyinc
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 5

Expert Comment

by:millsoft
ID: 10787384
What is the baseline for the integers?
0
 

Author Comment

by:luckyinc
ID: 10787408
This number is the number of SECONDS since 1970, 01, 01

It is stored into the database as an int (4)
0
 
LVL 4

Expert Comment

by:ATAHAC
ID: 10787429
If you know that 1077558217 is for ex: 01/01/2004
then 1077642495 is the date:
1077642495 - 1077558217 + cast('01/01/2004' as datetime)
0
 

Author Comment

by:luckyinc
ID: 10787467
Lets say the field name is

mydate

Criteria would be
mydate-1075400710 + Cast('01/29/2004' as datetime)
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 10787488
SELECT DATEADD(SECOND, yourIntValue, '1970-01-01')
0
 
LVL 5

Expert Comment

by:millsoft
ID: 10787495
e.g. print dateadd(ss, 1077641785, '01/01/1970')
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:luckyinc
ID: 10787500
How do I implement THIS FORMULA INTO SQL SERVER

MyFieldIntegerValue/86400+DATE(1970,1,1)
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 10787582
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.
0
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 100 total points
ID: 10787622
The earlier version:

SELECT DATEADD(SECOND, yourIntValue, '1970-01-01')

would give you a full time, including hours, minutes and seconds, which better matches your original request of:
"Convert UTC Date to MM/DD/YYYY HH MM SS"
0
 

Expert Comment

by:donschli
ID: 13450890
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.
0
 

Author Comment

by:luckyinc
ID: 13450945
I noticed that after I accepted the answer...where are you reposting the question?
0
 

Expert Comment

by:donschli
ID: 13450956
db/mssql
0
 

Expert Comment

by:donschli
ID: 13451019
Repost is Question Title: UTC int Convert to standard DateTime how?
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help with SQL Query 23 39
separate column 24 20
Convert int to military time 8 20
Stored procedure 23 0
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now