DTPERIOD

Purpose:

Calculates the difference between date and time series in years, months, days, hours, minutes and seconds.

Syntax:

DTPERIOD(date1, time1, date2, time2)

(yr, mo, dy, hr, mn, s) = DTPERIOD(date1, time1, date2, time2)

date1

-

A series of Julian integer dates, the end dates.

time1

-

A series of time of day values, the end times.

date2

-

Optional. A series of Julian integer dates, the start dates. Defaults to an empty series.

time2

-

Optional. A series of time of day values, the start times. Defaults to an empty series.

 

Alternate Syntax:

DTPERIOD(datetime1, datetime2)

(yr, mo, dy, hr, mn, s) = DTPERIOD(datetime1, datetime2)

datetime1

-

An array, the end datetimes where the date and time values are in adjacent columns.

datetime2

-

Optional. An array, the start datetimes where the date and time values are in adjacent columns. Defaults to an empty array.

Returns:

The elapsed period as an N x 6 series of years, months, days, hours, minutes, seconds.

 

(yr, mo, dy, hr, mn, s) = DTPERIOD(datetime1, datetime2) returns the values in separate variables.

 

If only one date and time series or one composite datetime series is specified, the periods are computed on the two-point difference of each datetime value.

Example:

W1: ymdhms2dt(2027, 1, 2, 12, 0, 0)

W2: ymdhms2dt(2027, 3, 1, 12, 0, 0)

W3: dtperiod(w2, w1)

W4: dtoffset(w1, w3)

 

W1 contains the datetime:

 

1/02/2027 12:00:00

 

W2 contains the datetime:

 

3/01/2027 12:00:00

 

W3 computes difference between the two datetimes in years, months, days, hours, minutes, seconds. The period is 0 years,1 month, 27 days, 0 hours, 0, minute and 0 seconds.

 

W4 recovers the end datetime by adding the offset in W3 to the startdate time in W1.

Example:

W1: ymdhms2dt(2028, 1, 2, 12, 0, 0)

W2: ymdhms2dt(2028, 3, 1, 12, 0, 0)

W3: dtperiod(w2, w1)

W4: dtoffset(w1, w3)

 

Same as the first example, except the end and start year is 2028, a leap year. The period is 0 years, 1 month, 28 days, 0 hours, 0, minute and 0 seconds. The days value has increased from 27 days to 28 days because of the leap year.

Example:

W1: ymdhms2dt(2027, 1, 2, 12, 0, 0)

W2: ymdhms2dt(2027, 3, 1, 12, 0, 0)

W3: dtperiod(w1, w2)

W4: dtoffset(w2, w3)

 

Same as the first example above, except the start and end date times are swapped. The result is a negative period, 0 years, -1 month, -30 days, 0 hours, 0 minutes and 0 seconds.

W4 reconstructs the earlier end datetime in W1 time by subtracting the offset in W3 to the later start datetime in W2.

Example:

W1: gnorm(10, 60*60*2 + 13)

W2: getdt(w1)

W3: dtperiod(w2)

 

W1 contains 10 random samples with a time spacing of 7213 seconds or 2 hours and 13 seconds between samples.

 

W2 computes the datetime values for each sample in W1.

 

Because only one datetime series was given, W3 computes the two-point difference between subsequent samples of W2. The result is 0 years, 0, months, 0 days, 2 hours, 0 minutes and 13 seconds for each sample, equal to the original sample spacing of the series in W1.

Example:

W1: ymdhms2dt(2001, 6, 3, 12, 10, 0.3)

W2: ymdhms2dt()

W3: dtperiod(w2, w1)

W4: dtoffset(w1, years:40)

W5: dtperiod(w4, w2)

 

W1 represents the datetime birthday of someone born on June 3, 2001 at 12:10:00.300.

W2 contains the current datetime.

W3 contains the current age of the person in years, months, days, hours, minutes and seconds.

W4 adds 40 years to the birthday in W1. The person will turn 40 on June 3, 2041 at 12:10:00.300.

W5 displays the number of years, months, days, hours, minutes and seconds remaining before their 40th birthday.

Remarks:

DTPERIOD computes the difference between two date and time series with the result in periods of years, months, days, hours, minutes and seconds.

 

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.

 

If only one date and time series or one composite datetime series is provided, the two-point period difference between subsequent date time series value is computed.

 

A date time period is measured in years, months, days, hours, minutes and seconds.

 

A date time duration is measured in seconds.

 

See DTDURATION to compute the time difference in seconds.

See Also:

DATEPERIOD

DTDIFF

DTDURATION

DTOFFSET

TIMEPERIOD

YMDHMS2DT