turn time in excel into epoch time for sql server 2000

  •  

    I need to apply the logic below in a sp on SQL Server 2000. I not sure how to code this. Can anyone give me some help? Thanks

    (DateOfInterest - 1/1/1970 03:00) *24 *60 *60 *1000 = n

  • note that the number of milliseconds will overflow an int value, so you've got to use a bigint datatype:

     

    declare @DateOfInterest datetime,

            @EpochDate datetime,

     @millisecs bigint

    set @DateOfInterest = '12/11/1962'

    set @EpochDate      = '1/1/1970 03:00'

    --select (@DateOfInterest - @EpochDate) *24 *60 *60 *1000  as n

    --causes overflow if you try and get milliseconds, because the function returns an INT:

    --select @millisecs=datediff(ms,@DateOfInterest,@EpochDate)

    select datediff(ss,@DateOfInterest,@EpochDate)

    select @millisecs=datediff(ss,@DateOfInterest,@EpochDate)

    --convert to milliseconds

    set @millisecs = @millisecs * 1000

    select @millisecs as [numOfMilliseconds]

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for your help!

  • Or... don't let it default to INT...

    declare @DateOfInterest datetime,

            @EpochDate datetime

    set @DateOfInterest = '12/11/1962'

    set @EpochDate      = '1/1/1970 03:00'

    select CAST((@DateOfInterest - @EpochDate) AS DECIMAL(24)) *24 *60 *60 *1000  as n

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Both worked great. Thanks for your help!

  • ...and thank you for the feedback...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply