当前位置:操作系统 > Unix/Linux >>

function to convert ticks to DatetimeOffset

function to convert ticks to DatetimeOffset
 
Sql代码  
--function to convert ticks to DatetimeOffset  
if  object_id(N'GetTimeFromTicks', N'FN') is null  
begin  
execute dbo.sp_executesql @statement = N'  
CREATE FUNCTION dbo.GetTimeFromTicks(@Ticks BIGINT)  
RETURNS DATETIME  
AS  
BEGIN  
DECLARE @Days BIGINT  
DECLARE @DaysBefore1753 BIGINT  
DECLARE @TimeTicks BIGINT  
DECLARE @Seconds BIGINT  
   
SET @Days = @Ticks / CONVERT(BIGINT,864000000000)  
SET @DaysBefore1753 = CONVERT(BIGINT,639905)  
SET @TimeTicks = @Ticks % CONVERT(BIGINT,864000000000)  
SET @Seconds = @TimeTicks / CONVERT(BIGINT,10000000)  
   
RETURN ToDateTimeOffSet(DATEADD(s,@Seconds,DATEADD(d,@Days - @DaysBefore1753,CONVERT(DATETIME,''1/1/1753''))), ''+00:00'')  
END'  
   
end  
 
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,