반응형

Convert Datetime to Unix timestamp

 

Convert Datetime to Unix timestamp

In Microsoft SQL Server 2012 or above, is it possible to convert a datetime value to Unix time stamp in a single select statement? If so, how can it be done?

stackoverflow.com

In Microsoft SQL Server 2012 or above, is it possible to convert a datetime value to Unix time stamp in a single select statement? If so, how can it be done?

 
use db

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



SELECT dbo.UNIX_TIMESTAMP(GETDATE()) ;

 

https://stackoverflow.com/questions/34455408/convert-datetime-to-unix-timestamp

 

 

How can I convert UNIX timestamp (bigint) to DateTime in SQL Server?

Select dateadd(S, 1637852002, '1970-01-01')

 

.

반응형

+ Recent posts