ms sql server中实现的unix时间戳函数(含生成和格式化,可以和mysql兼容)
程序员文章站
2023-10-20 10:16:43
直接上代码:
create function unix_timestamp (@ctimestamp datetime) returns integer...
直接上代码:
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 create function from_unixtime (@ts integer) returns datetime as begin /* function body */ declare @return datetime select @return = dateadd(second, @ts, {d '1970-01-01'}) return @return end
用法
跟mysql下的一样类似:
select dbo.unix_timestamp('2013-1-1') select dbo.from_unixtime(2145000000)