Skip to main content

Understanding Tag Historian Timestamps

Comments

4 comments

  • Eric Guadalupe

    For SQL Server, we can expand the example to retain milliseconds:

    DATEADD(ms, t_stamp % 1000, DATEADD(s, t_stamp / 1000, '1970-01-01'))

    1
  • Tyler Bennett

    For PostgreSQL...

    Usage: SELECT to_timestamp(t_stamp/1000.0) AS ts, * FROM sqlt_data_...

    •  Update 2023-11-10:  Changed `to_timestamp(t_stamp/1000)` to `to_timestamp(t_stamp/1000.0)` in order to retain milliseconds.

    It may also be useful to note that "standard" Unix Epoch time is the number of seconds since January 1, 1970 00:00:00 UTC. The Ignition variant uses milliseconds instead of seconds and that is why all the examples start by dividing the returned t_stamp value by 1000. 

    Reference:  https://forum.inductiveautomation.com/t/understanding-tag-historian-timestamps-in-postgresql/63663 

    0
  • Mohamed Dia

    How do we accommodate for the time zone in the MSSQL option?

    0
  • Nicholas Wyant

    (MSSQL)Here is what I have found to get the time adjusted for time zone:

    CONVERT(datetime, TODATETIMEOFFSET(DATEADD(s,t_stamp/1000, '1970-01-01), 0) AT TIME ZONE 'US Eastern Standard Time') AS Adjusted_Time

    0

Please sign in to leave a comment.

This article has 4 comments.