convert datetime to timestamp in ms sql server

在ms sql server中,把一个日期转换为时间戳:

源代码:

CREATE FUNCTION [dbo].[svf_UNIX_TIMESTAMP] 
(
    @ctimestamp DATETIME
)
RETURNS BIGINT
AS
BEGIN  
  DECLARE @return BIGINT

  SELECT @return = DATEDIFF_BIG(millisecond,'1970-01-01 00:00:00.000', @ctimestamp)

  RETURN @return
END
Source Code

 

实例:

 

posted @ 2022-06-14 09:02  Insus.NET  阅读(204)  评论(0编辑  收藏  举报