PHP date_interval_format

PHP date_interval_format


Definition : 

In php date_interval_format() Function is inbuilt function.PHP date_interval_format() function is used to format the interval of the given dates. It is an alias of DateInterval::format().

Syntax

    DateInterval::format(format)

Parameter:
Parameter Description
format Required. Specifies the format. The following characters can be used in the format parameter string:
  • % - Literal %
  • Y - Year, at least 2 digits with leading zero (e.g 03)
  • y - Year (e.g 3)
  • M - Month, with leading zero (e.g 06)
  • m - Month (e.g 6)
  • D - Day, with leading zero (e.g 09)
  • d - Day (e.g 9)
  • a - Total number of days as a result of date_diff()
  • H - Hours, with leading zero (e.g 08, 23)
  • h - Hours (e.g 8, 23)
  • I - Minutes, with leading zero (e.g 08, 23)
  • i - Minutes (e.g 8, 23)
  • S - Seconds, with leading zero (e.g 08, 23)
  • s - Seconds (e.g 8, 23)
  • F - Microseconds, at least 6 digits (e.g 004403, 235689)
  • f - Microseconds (e.g 4403, 235689)
  • R - Sign "-" when negative, "+" when positive
  • r - Sign "-" when negative, empty when positive

Note: Each format character must be prefixed by a % sign!

 Given below example Calculate the interval between two dates, then format the interval:

Output : 

Total number of days: 586.
Total number of days: +586.
Month: 7, days: 8.