Time interval¶
date & time
Calculates the duration of a time interval between two dates (datetimes/timestamps).
The dates can be specified either as two datetime columns (in which case the second is subtracted from the first),
or as a single column and a reference date provided as a parameter (see since
or until
in parameters below).
If only one column is provided as input, one of since
or until
must be specified as a reference date.
Usage¶
The following are the step's expected inputs and outputs and their specific types.
time_interval(
date1: date,
*date2: date,
{
"param": value
}
) -> (interval: number)
where the object {"param": value}
is optional in most cases and if present may contain any of the parameters described in the
corresponding section below.
Example¶
To get the positive number of hours since the last login of a user as of now:
time_interval(ds.last_login, {
"unit": "hours",
"until": "now",
}) -> (ds.hours_elapsed)
More examples
Using since
instead would lead to the same result but with negative hours:
time_interval(ds.last_login, {
"unit": "hours",
"since": "now",
}) -> (ds.hours_ago)
Inputs¶
date1: column:date
A column of datetimes.
*date2: column:date
An (optional) column of datetimes subtracted from the first.
Outputs¶
interval: column:number
The calculated interval in selected units.
Parameters¶
unit: string = "days"
The unit used to measure the duration of the intervals. Allowed unit specifiers are the codes and corresponding names in this table. If the full unit name is used, it can be spelled in any case as well as singular or plural. I.e. all of the following are equivalent: 'D', 'day', 'days', 'Day', 'Days'.
Must be one of:
"Y"
,
"year"
,
"Year"
,
"years"
,
"Years"
,
"M"
,
"month"
,
"Month"
,
"months"
,
"Months"
,
"W"
,
"week"
,
"Week"
,
"weeks"
,
"Weeks"
,
"D"
,
"day"
,
"Day"
,
"days"
,
"Days"
,
"h"
,
"hour"
,
"Hour"
,
"hours"
,
"Hours"
,
"m"
,
"minute"
,
"Minute"
,
"minutes"
,
"Minutes"
,
"s"
,
"second"
,
"Second"
,
"seconds"
,
"Seconds"
,
"ms"
,
"millisecond"
,
"Millisecond"
,
"milliseconds"
,
"Milliseconds"
,
"us"
,
"microsecond"
,
"Microsecond"
,
"microseconds"
,
"Microseconds"
,
"ns"
,
"nanosecond"
,
"Nanosecond"
,
"nanoseconds"
,
"Nanoseconds"
,
"ps"
,
"picosecond"
,
"Picosecond"
,
"picoseconds"
,
"Picoseconds"
,
"fs"
,
"femtosecond"
,
"Femtosecond"
,
"femtoseconds"
,
"Femtoseconds"
,
"as"
,
"attosecond"
,
"Attosecond"
,
"attoseconds"
,
"Attoseconds"
absolute: boolean = False
Return type of interval duration. Whether the interval duration should always be returned as positive, independent of whether date1
occurred before or after date2
since: string = "None"
Date start reference for intervals. If only one column is specified as input, a reference date relative to which the intervals will be calculated. The result will be date1 - since
. I.e. intervals will be positive if dates in the column are more recent than the reference date (and negative otherwise). The date must be either be a valid date string (preferrable month-first, e.g. "2021-12-31"), or any of the constants "today", "now", "tomorrow", "yesterday".
until: string = "None"
Date ending reference for intervals. If only one column is specified as input, a reference date relative to which the intervals will be calculated. The result will be until - date1
. I.e. intervals will be positive if the reference date is more recent than the dates in the column (and negative otherwise). The date must be either be a valid date string (preferrable month-first, e.g. "2021-12-31"), or any of the constants "today", "now", "tomorrow", "yesterday".