Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert int to datetime epoch 2

Status
Not open for further replies.

gtjr921

Programmer
Aug 30, 2006
115
I have a date field that is stored as an INT (yes an INT) I hate it,it's a 3rd party db. IT stores the date the same way some unix systems do.
IT stores the number of seconds since the epoch, or 1 January 1970. I am able to convert the int to date, but the time is off. It is actually ahead by 5 hours.
Example for this datetime as an int 1163517315
i get 2006-11-14 15:15:15.000, the correct time should be 10:16 am
the code i used to create my table is
Code:
alter TABLE [CDRMAin] add
    [starttimetimecalc] AS
 dateadd(second, endtime, '1 January 1970')

how can i correct this.
thanks
 
I think you need to subtract the number of seconds in five hours from endtime. Try this:

Code:
dateadd(second, (endtime - 18000), '1 January 1970')

Hope it helps,

Alex


A wise man once said
"The only thing normal about database guys is their tables".
 
Code:
alter TABLE [CDRMAin] add
    [starttimetimecalc] AS
 DateAdd(hh,-5,dateadd(second, endtime, '1 January 1970'))

?

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thank you for the star, but Alex code also should works.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top