Converts date and time values to internal timestamps.
DT2TIMESTAMP(date, time, "timezone")
date |
- |
Optional. A string or series of Julian integer dates, the input date. Defaults to the current date. |
time |
- |
Optional. A string or series of time of day values, the input time. Defaults to the current time. |
"timezone" |
- |
Optional. A string, the local time zone. Defaults to the current time zone. If specified, the resulting timestamps are based on UTC time. |
DT2TIMESTAMP(datetime, "timezone")
datetime |
- |
An array, a datetime series where the date and time values are in adjacent columns. |
"timezone" |
- |
Optional. A string, the local time zone. Defaults to the current time zone. If specified, the resulting timestamps are based on UTC time. |
A scalar or series of internal timestamps
ts = dt2timestamp("1/1/2021", "12:00:00");
dt = timestamp2dt(ts);
ts == 1609502400.0
dt == "1/1/2021 12:00:00.000"
W1: {julstr("1/1/1999"), julstr("1-10-1999"), julstr("4/2/1999")}
W2: {todstr("12:00"), todstr("14:00"), todstr("9:35")}
W3: dt2timestamp(w1, w2)
W4: timestamp2dt(w3)
W3 == {915192000.0, 915976800.0, 923045700.0}
W4 contains the datetime series:
01/01/1999 12:00:00.000
01/10/1999 14:00:00:000
04/02/1999 9:35:00.000
W1: {ymd2date(1999, 1, 1), ymd2date(1999, 1, 10), ymd2date(1999, 4, 2)}
W2: {hms2time(12, 0, 0), hms2time(14, 0, 0), hms2time(9, 35, 0)}
W3: dt2timestamp(w1, w2)
W4: timestamp2dt(w3)
Same as above, except the original date and time data are entered in YMD and HMS format.
W3 == {915192000.0, 915976800.0, 923045700.0}
W4 contains the datetime series:
01/01/1999 12:00:00.000
01/10/1999 14:00:00:000
04/02/1999 9:35:00.000
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 datetime values are 3 minutes earlier than the original timestamps in W2.
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 the original date time 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
W1: gnorm(1000, 1.0);settime(w0, "12:00:00")
W2: gnorm(1000, 1/2);settime(w0, "12:00:00")
W3: getdt(w1)
W4: getdt(w2)
W5: dt2timestamp(w3)
W6: dt2timestamp(w4)
W7: w5 - w6
W8: diff(w7)
W1 and W2 contain 1000 samples of random data both with a start time of noon.
The sample rate of W1 is 1 Hz and the sample rate of W2 is 2 Hz.
W3 and W4 obtain the datetime values for each sample of W1 and W2.
W5 and W6 convert the datetime data to timestamps.
W7 computes the time difference in seconds between each sample of W1 and W2. The time difference increases uniformly by 0.5 seconds indicating the samples of W1 lag the samples of W2 in time. For example, from W3 and W4:
Sample 6 of W1 occurs at 12:00:05.000
Sample 6 of W2 occurs at 12:00:02.500
Thus, sample 6 of W1 occurs 2.5 seconds later than sample 6 of W2.
W7 reports the same time difference of 2.5 seconds between sample 6 of W1 and W2.
W8 computes the difference between subsequent time lags. The difference is constant at 0.5 seconds indicating each sample of W1 lags W2 by an additional 0.5 seconds as time progresses. For example, from W3 and W4:
Sample 7 of W1 occurs at 12:00:06.000
Sample 7 of W2 occurs at 12:00:03.000
Sample 7 of W1 occurs 3.0 seconds later than sample 7 of W2. This is 0.5 seconds greater than the difference between samples 6 as previously shown.
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.
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 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.
As shown in the last example, DT2TIMESTAMP can be used to perform simple date/time arithmetic.
See TIMESTAMP2DT to convert an internal timestamp to a Julian date and clock time value.