?
Solved

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

Posted on 2004-04-08
13
Medium Priority
?
819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

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:Scott Pletcher
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
 

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:Scott Pletcher
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:
Scott Pletcher earned 400 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

770 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