#duration
DurationCreates a duration value from days, hours, minutes, and seconds components.
Syntax
#duration(days as number, hours as number, minutes as number, seconds as number) as durationParameters
| Name | Type | Required | Description |
|---|---|---|---|
days | number | Yes | The number of days in the duration. |
hours | number | Yes | The number of hours (added to the days component). |
minutes | number | Yes | The number of minutes (added to the hours component). |
seconds | number | Yes | The number of seconds (can include fractional seconds). |
Return Value
duration — A duration value representing the specified span of time.
Remarks
#duration is M's literal constructor for creating duration values — a span of time expressed as days, hours, minutes, and seconds.
All four arguments are additive and can be fractional. The total duration is the sum of all components: days * 86400 + hours * 3600 + minutes * 60 + seconds seconds.
Durations are most commonly obtained by subtracting two dates or datetimes of the same type. #duration lets you construct a specific span inline, useful for date arithmetic: adding 30 days (#duration(30, 0, 0, 0)), or representing a time interval.
Duration is not a number — you cannot multiply a duration by a scalar directly. Use Duration.TotalDays to convert to a number first, or Duration.From to construct from a total.
Examples
Example 1: Create a duration literal (1 day, 2 hours, 30 minutes)
#duration(1, 2, 30, 0)Result | |
|---|---|
| 1 | P1DT2H30M |
Example 2: Add a duration to a date
#date(2024, 1, 1) + #duration(30, 0, 0, 0)Result | |
|---|---|
| 1 | 1/31/2024 |
Example 3: Extract total hours from a duration
let
d = #duration(1, 6, 0, 0)
in
Duration.TotalHours(d)Result | |
|---|---|
| 1 | 30 |