UTC to datetime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amrit09
    New Member
    • Oct 2007
    • 2

    UTC to datetime

    Hi all

    I am currently running SQL server 2005. I have UTCs stored as a bigint and wish to convert these into a datetime. I am using:-

    SELECT DATEADD(mm, F1, '01/01/1970 00:00:00')

    The number coming from the F1 column is a 13digit number. When i run this query, i get the error:-

    Arithmetic overflow error converting expression to data type int.

    When i manually put in a number from the column, this still doesn't work, but, when i reduce the number to 10 digits the conversion does work.

    Can anyone help with getting the full number to convert?

    thanks
    AMRIT
  • azimmer
    Recognized Expert New Member
    • Jul 2007
    • 200

    #2
    Originally posted by amrit09
    Hi all

    I am currently running SQL server 2005. I have UTCs stored as a bigint and wish to convert these into a datetime. I am using:-

    SELECT DATEADD(mm, F1, '01/01/1970 00:00:00')

    The number coming from the F1 column is a 13digit number. When i run this query, i get the error:-

    Arithmetic overflow error converting expression to data type int.

    When i manually put in a number from the column, this still doesn't work, but, when i reduce the number to 10 digits the conversion does work.

    Can anyone help with getting the full number to convert?

    thanks
    AMRIT
    Firstly I suspect you meant:
    Code:
    SELECT     DATEADD([B]ms[/B], F1, '01/01/1970 00:00:00')
    I would consider converting F1 to a longer timescale first and then add it, like this (if F1 is indeed milliseconds):
    Code:
    SELECT     DATEADD(s, F1/1000, '01/01/1970 00:00:00')

    Comment

    • amrit09
      New Member
      • Oct 2007
      • 2

      #3
      Thanks, will try it

      AMRIT

      Comment

      Working...