Convert to Unix Timestamp

How Can We Help?

You are here:
< Back

Converting a datetime to unix timestamp is easy, but involves error prone typing the following:

@timestamp=DATEDIFF(second,{d '1970-01-01'},@datetime)

Where @datetime is the datetime value you want to convert. The {d ‘yyyy-mm-dd’} notation is an ODBC escape sequence.

The function:

CREATE FUNCTION UNIX_TIMESTAMP (
@ctimestamp datetime
)
RETURNS integer
AS
BEGIN
/* Function body */
declare @return integer

SELECT @return = DATEDIFF(SECOND,{d '1970-01-01'}, @ctimestamp)

return @return
END

 

Information found here: http://stackoverflow.com/questions/34455408/convert-datetime-to-unix-timestamp