Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP date_interval_format()/DateInterval::format() Function

PHP date_interval_format() Function

PHP Date/Time PHP Date/Time Reference Manual

Calculate the interval between two dates, then format the interval:

Example

format ( "Total number of days in the interval: %a days." ); ?>

Run Example »


Definition and Usage

The date_interval_format() function is an alias of DateInterval::format().

The DateInterval::format() function formats a time interval.

Syntax

DateInterval::format(

format);

Parameters Description
format Required. Specifies the format.format The parameter string can use the following characters:
  • % - Literal %
  • Y - Years, at least 2 digits with leading zeros (for example 03)
  • y - Years (for example 3)
  • M - Months, with leading zeros (for example 06)
  • m - Months (for example 6)
  • D - Days, with leading zeros (for example 09)
  • d - Days (for example 9)
  • a - Total number of days in the interval between two dates, as returned by date_diff()
  • H - Hours, with leading zeros (for example 08, 23)
  • h - Hours (for example 8, 23)
  • I - Minutes, with leading zeros (for example 08, 23)
  • i - Minutes (for example 8, 23)
  • S - Seconds, with leading zeros (for example 08, 23)
  • s - Seconds (for example 8, 23)
  • R - The sign "-" when negative, "+" when positive
  • r - The sign "-" when negative, empty when positive
  • Note:Every format string must be prefixed with a % sign!

    |

    Technical Details

    Return Value: Returns the formatted time interval.
    PHP Version: 5.3+

    PHP Date/Time PHP Date/Time Reference Manual