Skip to main content

Duration

A duration variable represents a period of time such as 3 days or 4 and a half minutes in ISO 8601 duration format

Construction

A duration can be constructed using a code or by subtracting 2 dates

// Construct a duration of 1 day
oneday = Duration("1D")

// Subtract 2 dates to create a duration
d1 = Date("2020-06-08")
d2 = Date("2020-06-09")
dur1D = d2 - d1

Duration code

A duration code is comprised of a list of periods of time defined in the table below:

PeriodDescription
sSeconds
mMinutes
hHours
DDays
WWeeks
MMonths
YYears

Each period has a number and a period code, e.g. 1D is 1 day

Here are some examples:

CodeAmount of time
1D1 day
4h30m4 and 1/2 hours
60h60 hours
2M2 months
1Y2M12D6h30m1 year, 2 months, 12 days, 6 hours and 30 minutes
12W12 weeks

Properties

The following is a list of properties on a duration variable:

NameDescriptionType
yearsThe number of defined years in this durationScalar(Integer)
monthsThe number of defined months in this durationScalar(Integer)
daysThe number of defined days in this durationScalar(Integer)
hoursThe number of defined hours in this durationScalar(Integer)
minutesThe number of defined minutes in this durationScalar(Integer)
secondsThe number of defined seconds in this durationScalar(Integer)