Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

date_interval_format

Description

The date_interval_format of Date / Time for PHP formats the interval.

Syntax

date_interval_format ( DateInterval $object , string $format ) : string

Parameters

object

A DateInterval object.

format

CharacterDescriptionExample
%Literal %%
YYears, numeric, at least 2 digits with leading 001, 03
yYears, numeric1, 3
MMonths, numeric, at least 2 digits with leading 001, 03, 12
mMonths, numeric1, 3, 12
DDays, numeric, at least 2 digits with leading 001, 03, 31
dDays, numeric1, 3, 31
aTotal number of days as a result of a DateTime::diff() or (unknown) otherwise4, 18, 8123
HHours, numeric, at least 2 digits with leading 001, 03, 23
hHours, numeric1, 3, 23
IMinutes, numeric, at least 2 digits with leading 001, 03, 59
iMinutes, numeric1, 3, 59
SSeconds, numeric, at least 2 digits with leading 001, 03, 57
sSeconds, numeric1, 3, 57
FMicroseconds, numeric, at least 6 digits with leading 0007701, 052738, 428291
fMicroseconds, numeric7701, 52738, 428291
RSign "-" when negative, "+" when positive-, +
rSign "-" when negative, empty when positive-,

Return

Returns the formatted interval.

Examples

1

<?

$object = date_interval_create_from_date_string("1 year 1 month 1 day 1 hour 1 minute 1 second");
$format = "years: %y\nmonths: %m\ndays: %d\nhours: %h\nminutes: %i\nseconds: %s";

$return = date_interval_format($object, $format);

echo $return;

?>
years: 1
months: 1
days: 1
hours: 1
minutes: 1
seconds: 1

2

<?

$originObject = date_create("2001-01-01");
$targetObject = date_create();

$object = date_diff($originObject, $targetObject);
$format = "years: %y\nmonths: %m\ndays: %d\nhours: %h\nminutes: %i\nseconds: %s";

$return = date_interval_format($object, $format);

echo $return;

?>
years: 23
months: 9
days: 13
hours: 12
minutes: 20
seconds: 41
HomeMenu