直接上代码:
sql;">
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下的一样类似:
sql;">
select dbo.UNIX_TIMESTAMP('2013-1-1')
select dbo.from_unixtime(2145000000)
原文链接:https://www.f2er.com/mssql/63252.html