2013-09-25 186 views
0

我想將ms sql服務器中的日期類型轉換爲毫秒,這裏是我試過的。我完全是新的MS SQL服務器,並會欣賞有人幫助。如何將日期更改爲毫秒毫秒SQL服務器

SELECT datediff(ms,date(),a.ReportDate), a.Peak 
from [RealTimeUsage] a 
where exists(
    select top 10 * from 
    CustomerPortal.dbo.users b, CustomerPortal.dbo.UsersDevice c 
    where (b.useridid = c.useridid) order by a.ReportDate 
) 
+1

問題是?這與你期望/需要的結果有何不同? –

+0

問題是,當我查詢運行此查詢時,它不顯示任何毫秒。它什麼都沒顯示 –

回答

0

sql-server中沒有構建函數date()。如果你想在當前日期,請嘗試使用GETDATE()函數

SELECT DATEDIFF(MS,GETDATE(),a.ReportDate),a.Peak
FROM [RealTimeUsage]一個
WHERE EXISTS(
SELECT TOP 10 * FROM
CustomerPortal.dbo.users b,CustomerPortal.dbo.UsersDeviceç
WHERE(b.useridid = c.useridid)ORDER BY a.ReportDate

和DATEDIFF()語法是 DATEDIFF (datepart,startdate,enddate) enddate將是第三個參數,startdate將是第二個(如果您錯誤地給出了它)