none
Convert a date to milliseconds

    Question

  • 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
    Wednesday, September 25, 2013 7:29 PM

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]signature

    Wednesday, September 25, 2013 8:39 PM
    Moderator
  • SELECT  datediff(ms,getdate(),a.ReportDate) as msCol,...

    SELECT  datediff(ms,current_timestamp,a.ReportDate) as msCol,

    Wednesday, September 25, 2013 9:49 PM
    Moderator

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]signature

    Wednesday, September 25, 2013 8:39 PM
    Moderator
  • SELECT  datediff(ms,getdate(),a.ReportDate) as msCol,...

    SELECT  datediff(ms,current_timestamp,a.ReportDate) as msCol,

    Wednesday, September 25, 2013 9:49 PM
    Moderator