TIMESTAMP2DT

Purpose:

Converts internal timestamps to a datetime series.

Syntax:

TIMESTAMP2DT(ts, "timezone")

(date, time) = TIMESTAMP2DT(ts, "timezone")

ts

-

A series of internal timestamps.

"timezone"

-

Optional. A string, the local time zone. Defaults to the current time zone. If specified, the resulting date time values are based on the UTC time offset from the specified timezone.

Returns:

A datetime series where the data and time values are in two adjacent columns.

 

(date, time) = TIMESTAMP2DT(ts, "timezone") returns the date and time in two separate variables.

Example:

W1: {1407159000, 1408159082, 1411150163, 1417159180, 1427159240}

W2: timestamp2dt(W1)

 

W2 contains the datetime series:

 

 8/04/2014  13:30:00

 8/16/2014   3:18:02

 9/19/2014  18:09:23

11/28/2014   7:19:40

 3/24/2015   1:07:20

Example:

W3: {1407159000, 1408159082, 1411150163, 1417159180, 1427159240}

W4: (d, t) = timestamp2dt(W3);ravel(d, t);table

 

W4 contains the datetime series:

 

 8/04/2014  13:30:00

 8/16/2014   3:18:02

 9/19/2014  18:09:23

11/28/2014   7:19:40

 3/24/2015   1:07:20

Example:

W1: grand(3, 1);settime(w0, "0:00:00.125");setdate(w0, "12/01/2024")

W2: getdt(w1)

W3: dt2timestamp(w2) - 60 * 3

W4: timestamp2dt(w3)

 

W1 contains a 3 sample random series with a start date of 125 milliseconds after midnight on 12/1/2024.

 

W2 obtains the date and time values for each sample in W1 and contains the datetime series:

 

12/01/2024  0:00:00.125

12/01/2024  0:00:01.125

12/01/2024  0:00:02.125

 

W3 converts the datetime values in W2 into timestamps. The timestamps are decreased by 180 seconds or 3 minutes.

 

W3 == {1733011020.125, 1733011021.125, 1733011022.125}

 

W4 converts the modified timestamps in W3 into datetime values and contains:

 

11/30/2024  23:57:00.125

11/30/2024  23:57:01.125

11/30/2024  23:57:02.125

 

The resulting date and time values are 3 minutes earlier than the original timestamps in W2.

Example:

W1: grand(3, 1);settime(w0, "0:00:00.125");setdate(w0, "12/01/2024")

W2: getdt(w1)

W3: dt2timestamp(w2, "America/New_York") - 60 * 3

W4: timestamp2dt(w3, "America/Los_Angeles")

 

Same as above except now the original datetime values are marked as having originated in the Eastern Time zone. The values are increased by 3 minutes and then converted into datetime values in the Pacific Time zone.

 

W4 contains the datetime series:

 

11/30/2024  20:57:00.125

11/30/2024  20:57:01.125

11/30/2024  20:57:02.125

Remarks:

An internal timestamp is a real value that represents the number of seconds that have elapsed since midnight January 1, 1970 UTC time. The integer part is the whole number of days and the fractional part is the fraction of a day. TIMESTAMP2DT converts the internal second values into date and clock time for the day.

 

A datetime series consists of 2 columns of values where the first column contains integer Julian dates starting at midnight and the second column contains time in seconds starting from midnight.

 

The timezone string is case sensitive and should adhere to the IANA timezone identifiers available at:

 

https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

and:

https://www.iana.org/time-zones

 

If timezone is blank or "local", the local time zone is used.

 

If timezone is specified when using DT2TIMESTAMP and TIMESTAMP2DT, the input and output values are converted to and from UTC time. When the timestamps are used to perform date time arithmetic, the results properly account for Daylight Savings time changes, however at decreased performance for large inputs.

 

See DT2TIMESTAMP to convert a datetime series to internal timestamps.

See Also:

DT2EXCEL

DT2TIMESTAMP

DT2UNIX

DT2YMDHMS

DTDURATION

DTPERIOD

GETDT

EXCEL2DT

UNIX2DT