Adds or subtracts years, months, days, hours, minutes and seconds to date and time values.
DTOFFSET(datetime, years, months, days, hours, minutes, seconds)
datetime |
- |
A datetime series where the date and time values are in adjacent columns. |
years |
- |
A scalar or series, the year values. Defaults to 0. |
months |
- |
A scalar or series, the month values. Defaults to 0. |
days |
- |
A scalar or series, the day values. Defaults to 0. |
hours |
- |
A scalar or series, the hours values. Defaults to 0. |
minutes |
- |
A scalar or series, the minutes values. Defaults to 0. |
seconds |
- |
A scalar or series, the seconds values. Defaults to 0. |
DTOFFSET(date, time, years, months, days, hours, minutes, seconds)
date |
- |
A date series. |
time |
- |
A time series. |
years |
- |
A scalar or series, the year values. Defaults to 0. |
months |
- |
A scalar or series, the month values. Defaults to 0. |
days |
- |
A scalar or series, the day values. Defaults to 0. |
hours |
- |
A scalar or series, the hours values. Defaults to 0. |
minutes |
- |
A scalar or series, the minutes values. Defaults to 0. |
seconds |
- |
A scalar or series, the seconds values. Defaults to 0. |
A datetime series.
W1: ymdhms2dt(2030, 1, 1, 12, 0, 0)
W2: dtoffset(w1, 1, 1, 1, 1, 1, 1)
W1 contains the datetime series:
1/1/2030 12:00:00
W2 adds 1 year, 1 month, 1 day, 1 hour, 1 minute and 1 second to the datetime in W1. The resulting datetime is:
2/2/2031 13:01:01
W1: ymdhms2dt(2030, 1, 1, 12, 0, 0)
W2: dtoffset(w1, 1, 1, 1, 1, 1, 1)
W3: dtoffset(w2, -1, -1, -1, -1, -1, -1)
Same as above except W3 removes the offset in W2 to return the same datetime as in W1:
1/1/2030 12:00:00
W1: grand(3, 1);setdate(w0, "1/1/2030");settime(w0, "12:00:00")
W2: getdt(w1)
W3: dtoffset(w2, days:-3, hours:1..3)
W1 generates a 3 point random series sampled at 1 sample per second. The start date is set to 1-1-2030 and the start time is 12:00:00.
W2 obtains the datetime values for each sample of W1. W2 contains the datetime values:
1/01/2030 12:00:01
1/01/2030 12:00:02
1/01/2030 12:00:03
W3 subtracts 3 days from each datetime value and adds 1 hour to the first value, 2 hours to the second value and 3 hours to the last datetime value. The offset values are specified using the Parameter:Value syntax. The resulting datetime values are:
12/29/2029 13:00:00
12/29/2029 14:00:01
12/29/2029 15:00:02
W1: grand(3, 1);setdate(w0, "1/1/2030");settime(w0, "12:00:00")
W2: getdt(w1)
W3: dtoffset(w2, days:-3, hours:1..3)
W4: dtperiod(w2, w3)
W5: dtoffset(w3, w4)
W6: w2 == w5
Same as above, except W4 computes the period in years, months, days, hours, minutes and seconds between the datetime values in W2 and the datetime values in W3. The difference is 2 days and 23 hours for the first value, 2 days and 22 hours for the second value and 2 days 21 hours for the last value.
W5 adds the offset values in W4 to the datetime values in W3. The resulting datetime values are the same as the original values in W2. In this case, subtracting 3 days and adding 1, 2 and 3 hours to the datetime values in W2 is the same as subtracting 2 days and subtracting 23, 22, and 21 hours to the datetime values in W2,
W6 compares the datetime values of W2 and W5, verifying the values are identical.
DTOFFSET adds or subtracts years, months, days, hours, minutes and seconds from a datetime series.
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 offset values can be specified using the Parameter:Value syntax. For example:
dtoffset(dt, minutes:5, months:3)
adds 3 months and 5 minutes to the date time series dt.
The offset values are always added in years, months, days, hours, minutes and seconds order.