Solved

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

Posted on 2004-04-08
13
814 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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.
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

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