你確定你需要它達到毫秒(千分之一秒)嗎?
注意1天= 86,400,000ms(是86.4萬美元)
1年=約31.6十億毫秒。
1970年(截至今天)44年前,所以大約是1.4萬億毫秒前。
當然,一個BIGINT可以處理它,不幸的是你還打DATEDIFF
的限制,這裏是從文檔報價:
If the return value is out of range for int (-2,147,483,648 to +2,147,483,647), an error is returned. For millisecond, the maximum difference between startdate and enddate is 24 days, 20 hours, 31 minutes and 23.647 seconds. For second, the maximum difference is 68 years.
所以,你的安全得到以秒之差了一會(只要你不走太遠的將來),然後你可以從今天開始,例如數毫秒:
SELECT
CAST(DATEDIFF(second, '1970-01-01', CAST(GetUtcDate() AS date)) AS bigint)
AS [SecondsToStartOfDay],
DATEDIFF(ms, CAST(GetUtcDate() AS date), GetUtcDate())
AS [MillisecondsSinceStartOfDay],
(CAST(DATEDIFF(second, '1970-01-01', CAST(GetUtcDate() AS date)) AS bigint)*1000)
+ DATEDIFF(ms, CAST(GetUtcDate() AS date), GetUtcDate())
AS [Milliseconds]
前兩列都只是爲了顯示涉及的步驟。
你仍然不知道你是否得到了足夠的接受有效的答案嗎? – Kangkan
Oracle SQL版本:http://stackoverflow.com/q/31652232/435605 –