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
 Transact-SQL (2000)
 Unixt Time Conversion on MSSQL

Author  Topic 

jay_gonzales
Starting Member

1 Post

Posted - 2005-02-01 : 02:52:44
Hi,
Is there a way to convert a unixtime format to datetime on MSSQL platform ?

Thanks alot,

Jay

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2005-02-01 : 04:09:57
there is a way to convert a string of characters to SS datetime:

convert(datetime, '20050131')
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-02-01 : 04:33:39
quote:
Originally posted by Stoad

there is a way to convert a string of characters to SS datetime:

convert(datetime, '20050131')



Unixtime is the number of seconds elapsed since the unix epoch (jan 1, 1970).

you can convert unixtime to Sql server time with the following code:


DECLARE @utc INT
SET @utc= 1107216000 -- todays date in unix time/utc
SELECT DATEADD(dd, (@utc/86400), '1/1/1970')




-ec
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2005-02-01 : 07:08:09
Tara has posted a udf which performs this conversion also:

http://weblogs.sqlteam.com/tarad/archive/2003/11/10/473.aspx
Go to Top of Page
   

- Advertisement -