How to use ISO duration
How to Use ISO 8601 Duration Format
The ISO 8601 duration format allows you to represent durations of time in a standardized way. For example, if your data records contain a mixture of duration (e.g. 3 days, 4 months, 1 year etc.) you can represent all of these values using the ISO standard duration. Read more about using the ISO date/time standard for your other data formats.
The ISO standard duration format is `PnYnMnDTnHnMnS`, where:
– `P` indicates the period (required).
– `nY` indicates the number of years.
– `nM` indicates the number of months.
– `nW` indicates the number of weeks.
– `nD` indicates the number of days.
– `T` separates the date and time components.
– `nH` indicates the number of hours.
– `nM` indicates the number of minutes.
– `nS` indicates the number of seconds.
Examples
One Year, Two Months, and Three Days:
– Format: `P1Y2M3D`
Six Months:
– Format: `P6M`
Four Weeks:
– Format: `P4W`
Three Hours, Fifteen Minutes, and Thirty Seconds:
– Format: `PT3H15M30S`
Two Years and Six Months:
– Format: `P2Y6M`
One Day and Twelve Hours:
– Format: `P1DT12H`
Forty-Five Seconds:
– Format: `PT45S`
Two Days, Three Hours, Four Minutes, and Five Seconds:
– Format: `P2DT3H4M5S`
One Year, Two Months, Three Days, Four Hours, Five Minutes, and Six Seconds:
– Format: `P1Y2M3DT4H5M6S`
Tips
– The `P` is mandatory and indicates that the following string defines a period.
– The `T` is used to separate the date and time components.
– Any of the components (`Y`, `M`, `W`, `D`, `H`, `M`, `S`) can be omitted if they are not needed.
– Ensure that the order of components is preserved: years, months, weeks, days, hours, minutes, and seconds.
When writing your schema using Semantic Engine duration is supported as a data format. Choose DateTime as a datatype to have this option available when adding a format feature.
Using these examples and tips, you can accurately represent various durations in the ISO 8601 format.
Written by Carly Huitema