2013-01-24 50 views
0

我嘗試使用需要的日期展鵬產品在蜱即634925952000000000 = 2013年1月1日00:00:00蜱在SQL爲1901年1月1日00:00:00

我可以找到一個轉換器工作出01/01/1901 00:00:00在sql

沒有發生這種情況「datediff函數導致溢出。日期分隔兩個日期/時間實例的數量太大。嘗試使用datediff與不太精確的日期部分。「

SELECT DATEDIFF(s, '19010101', GETDATE())*1000000 

答案沒有誰能幫助。

只是值爲01/01/1901 00:00:00真正的應用程序使用它作爲空日期。

回答

3

的那些2日期間返回的秒數太多的DATEDIFF數據類型以支持這是一個int。我已經看到其他人在幾分鐘內使用差異,然後使用BigInt轉換爲秒。

嘗試這樣:

SELECT DATEDIFF(mi,'19010101',getDate()) * CONVERT(BIGINT,60) 

這裏的SQL Fiddle

祝你好運。

+0

OP想要這個結果'01/01/1901 00:00:00' :) – spajce

0

試試下面的查詢......可能是它可以幫助你......

DECLARE @date datetime 
DECLARE @ticksperday bigint 
set @date = getdate() 
set @ticksPerDay = 864000000000 
declare @date2 datetime2 = getdate() 
declare @dateBinary binary(9) = cast(reverse(cast(@date2 as binary(9))) as binary(9)) 
declare @days bigint = cast(substring(@dateBinary, 1, 3) as bigint) 
declare @time bigint = cast(substring(@dateBinary, 4, 5) as bigint) 

select @date as [DateTime], @date2 as [DateTime2], @days * @ticksPerDay + @time as [Ticks] 
0

聽起來像是你想要datetimeconversion

SELECT CONVERT(VARCHAR, datetick, 120) FROM supportContacts 

DEMO

+0

Spajce,我需要tick值出來1901-01-01 – icecurtain

+0

請檢查http://stackoverflow.com/questions/2892447 /轉換最新到蜱,在-SQL服務器 – spajce

0

599581440000000000是來回以上解決方案的一些原因值想出了這個。

相關問題