Solved

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

Posted on 2004-04-08
13
812 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

832 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