Answered by:
Convert a date to milliseconds

-
I would like to convert a date to milliseconds to feed a plot chart that I'm using. Can someone tell me where to start. Here's what I tried to do. Please be gentle I come from a Linux background and only have just started using ms sql server.
GIN
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
)- Edited by Ghosteyes999 Wednesday, September 25, 2013 7:41 PM
Question
Answers
-
you can use DATEDIFF function to get the time in millisecond from specific time (not from dynamic time like date()). for example you can use '20000101' or any time you can be sure is before the first time that you have in the data. this will be like converting to millisecond and you can always go back using the same function with opposite value.
[Personal Site] [Blog] [Facebook]
- Proposed as answer by Allen Li - MSFTModerator Friday, September 27, 2013 8:56 AM
- Marked as answer by Allen Li - MSFTModerator Thursday, October 03, 2013 8:00 AM
-
SELECT datediff(ms,getdate(),a.ReportDate) as msCol,...
SELECT datediff(ms,current_timestamp,a.ReportDate) as msCol,
- Proposed as answer by Allen Li - MSFTModerator Friday, September 27, 2013 8:56 AM
- Marked as answer by Allen Li - MSFTModerator Thursday, October 03, 2013 8:00 AM
All replies
-
you can use DATEDIFF function to get the time in millisecond from specific time (not from dynamic time like date()). for example you can use '20000101' or any time you can be sure is before the first time that you have in the data. this will be like converting to millisecond and you can always go back using the same function with opposite value.
[Personal Site] [Blog] [Facebook]
- Proposed as answer by Allen Li - MSFTModerator Friday, September 27, 2013 8:56 AM
- Marked as answer by Allen Li - MSFTModerator Thursday, October 03, 2013 8:00 AM
-
SELECT datediff(ms,getdate(),a.ReportDate) as msCol,...
SELECT datediff(ms,current_timestamp,a.ReportDate) as msCol,
- Proposed as answer by Allen Li - MSFTModerator Friday, September 27, 2013 8:56 AM
- Marked as answer by Allen Li - MSFTModerator Thursday, October 03, 2013 8:00 AM