PHP date_interval_format() Function

Definition

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

The DateInterval::format() function is used to format the interval.

Syntax

PHP date_interval_format() Function has the following syntax.

DateInterval::format(format);

Parameter

ParameterIs RequiredDescription
formatRequired.Specifies the format.

The following characters can be used in the format parameter string:

FormatMeaning
%Literal %
YYear, at least 2 digits with leading zero (e.g 03)
yYear (e.g 3)
MMonth, with leading zero (e.g 06)
mMonth (e.g 6)
DDay, with leading zero (e.g 09)
dDay (e.g 9)
aTotal number of days as a result of date_diff()
HHours, with leading zero (e.g 08, 23)
hHours (e.g 8, 23)
IMinutes, with leading zero (e.g 08, 23)
iMinutes (e.g 8, 23)
SSeconds, with leading zero (e.g 08, 23)
sSeconds (e.g 8, 23)
RSign "-" when negative, "+" when positive
rSign "-" when negative, empty when positive

Note

PHP date_interval_format() Function Each format character must be prefixed by a % sign!

Return

PHP date_interval_format() Function returns the formatted interval.

Example

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


<?php/*from  w ww  .  j  a va 2 s .  c om*/
$date1=date_create("2013-01-01");
$date2=date_create("2013-02-10");
$diff=date_diff($date1,$date2);

// %a outputs the total number of days
echo $diff->format("Total number of days: %a.");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions