If you miss the from_unixtime() of mysql in MS SQL Server, then create these functions and enjoy.
The longtodate() function takes the number of milliseconds from epoch (Jan 1, 1970) and gives you the value in DATETIME format. To convert a DATETIME field to a unix timestamp use the datetolong() function
II datetolong function
The longtodate() function takes the number of milliseconds from epoch (Jan 1, 1970) and gives you the value in DATETIME format. To convert a DATETIME field to a unix timestamp use the datetolong() function
I. longtodate function
CREATE FUNCTION longtodate(@utc BIGINT)RETURNS DATETIMEASBEGINRETURN DATEADD(MILLISECOND, @utc % 1000, DATEADD(SECOND, @utc / 1000, '19700101'))END
CREATE FUNCTION datetolong(@date DATETIME)RETURNS BIGINTASBEGINRETURN CAST(DATEDIFF(s,'1970-01-01',@date) AS bigint) * 1000;END
Comments
Post a Comment