UNIX_TIMESTAMP in SQL Server

后端 未结 8 1954
陌清茗
陌清茗 2020-12-01 15:45

I need to create a function in SQL Server 2008 that will mimic mysql\'s UNIX_TIMESTAMP().

Thanks in advance !

8条回答
  •  一整个雨季
    2020-12-01 16:20

    If you're not bothered about dates before 1970, or millisecond precision, just do:

    -- SQL Server
    SELECT DATEDIFF(s, '1970-01-01 00:00:00', DateField)
    

    Almost as simple as MySQL's built-in function:

    -- MySQL
    SELECT UNIX_TIMESTAMP(DateField);
    

    Other languages (Oracle, PostgreSQL, etc): How to get the current epoch time in ...

提交回复
热议问题