Solved

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

Posted on 2004-04-08
13
815 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

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 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating a SQLServer BI cube from Oracle data source 4 37
SQL Procedure 7 44
Use SSRS to email customers? 4 21
invoke-sqlcmd help 5 23
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

740 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