toIso8601Duration.php
Table of Contents
Functions
- toIso8601Duration() : string
- Converts a DateInterval object to its ISO 8601 duration string representation.
Functions
toIso8601Duration()
Converts a DateInterval object to its ISO 8601 duration string representation.
toIso8601Duration(DateInterval $interval) : string
This function generates a normalized ISO 8601 duration string from a PHP DateInterval object. The ISO 8601 duration format follows the pattern: P[n]Y[n]M[n]DT[n]H[n]M[n]S where P is the duration designator, T separates date and time components.
Components:
- Y: years
- M: months (before T) or minutes (after T)
- D: days
- H: hours
- M: minutes
- S: seconds
Only non-zero components are included in the output string. If all components are zero, returns "P0D" (zero duration).
Parameters
- $interval : DateInterval
-
The DateInterval object to convert
Tags
Return values
string —The ISO 8601 duration string (e.g., "P1Y2M3DT4H5M6S", "PT30M", "P0D")