MS SQL Convert unix timestamp to date time

1. February 2011 18:51

 

It's something that all of a sudden when you think you need it. You cant think of how to do it.

So here is a quick function that turns a unix timestamp into a datetime

 

CREATE FUNCTION [dbo].[UNIXToDateTime] (@timestamp int)
	RETURNS datetime
AS
BEGIN
	DECLARE @ret datetime
	
	SELECT @ret = DATEADD(second, @timestamp, '1970/01/01 00:00:00')
	
	RETURN @ret
END
GO

An example on how to use it

 

SELECT dbo.UNIXToDateTime(dbo.DateTimeToUNIX(GETDATE()))

You may also want to see the convert to unix timstamp function

E-mail Kick it! DZone it! del.icio.us Permalink


Pingbacks and trackbacks (1)+

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading