Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Convert number of seconds to date format!!!!

Author  Topic 

missinglct
Yak Posting Veteran

75 Posts

Posted - 2004-09-07 : 09:26:57
Hi all,
I have a fieldname in SQL Server that stores number of seconds.
Is there a script/command that can convert the number of seconds since 1/1/1970 to the "date" format?
Ex: 1071541212 = 1/2/2004

Thanks,


spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-07 : 09:38:08
maybe something like this...
but this gives me 2003-12-16

declare @secs int
set @secs = 1071541212
select @secs/86400, dateadd(d, @secs/86400, '1.1.1970')

hope it helps in some way...

<edit>
simpler: select dateadd(s, @secs, '1.1.1970')

Go with the flow & have fun! Else fight the flow
Go to Top of Page

missinglct
Yak Posting Veteran

75 Posts

Posted - 2004-09-07 : 11:29:28
quote:
Originally posted by spirit1

maybe something like this...
but this gives me 2003-12-16

declare @secs int
set @secs = 1071541212
select @secs/86400, dateadd(d, @secs/86400, '1.1.1970')

hope it helps in some way...

<edit>
simpler: select dateadd(s, @secs, '1.1.1970')

Go with the flow & have fun! Else fight the flow



It helps. Thx.

Here is another link I found useful in case someone else has the same question.
http://www.techonthenet.com/access/functions/date/dateadd.htm

Go to Top of Page
   

- Advertisement -