Returns the total number of days (only for intervals from date_diff()).
date_interval_format($interval, "%H:%I:%S")
Returns the time part with leading zeros, such as 02:05:09.
Lowercase codes (%d, %h, %i, %s) print plain numbers, while uppercase codes (%D, %H, %I, %S) add a leading zero. Use %% to print a percent sign. %a only works when the interval came from date_diff(); otherwise it prints (unknown).
The two times are on the same day, so the interval is 2 hours, 5 minutes, and 9 seconds.
Uppercase %H, %I, and %S always use two digits, so you get 02:05:09.
Lowercase %h and %i print the plain numbers 2 and 5.
Choose uppercase for clocks and lowercase for sentences.
Frequently Asked Questions
It converts a DateInterval into a string using format codes. For example, "%d days" becomes "14 days" when the interval has 14 days.
%a is the total number of days between two dates. It only works for intervals returned by date_diff(). For other intervals it prints (unknown).
%d prints the number as is, like 5. %D pads it with a leading zero to at least two digits, like 05. The same pattern applies to %H, %I, %S, and %M.
In interval formats, %m is months and %i is minutes. This is different from date(), where i is minutes and n or m are months, so double-check your codes.
Yes. The procedural function is an alias of the format() method on DateInterval, and both return the same text.