ms sql server中实现的unix时间戳函数(含生成和格式化,可以和mysql兼容)
时间:2020-10-31 14:26 作者:admin
直接上代码:
CREATE FUNCTION UNIX_TIMESTAMP (@ctimestamp datetime) RETURNS integer ASBEGIN /* Function body */ declare @return integer SELECT @return = DATEDIFF(SECOND,{d '1970-01-01'}, @ctimestamp) return @returnENDCREATE FUNCTION from_unixtime (@ts integer) RETURNS datetime ASBEGIN /* Function body */ declare @return datetime select @return = DATEADD(second, @ts, {d '1970-01-01'}) return @returnEND
用法
跟mysql/' target='_blank'>mysql下的一样类似:
select dbo.UNIX_TIMESTAMP('2013-1-1')select dbo.from_unixtime(2145000000)
(责任编辑:admin)