International PHP Conference Munich 2021


(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)

IntlCalendar::fieldDifferenceCalculate difference between given time and this objectʼs time


Stil obiect-orientat

public IntlCalendar::fieldDifference ( float $when , int $field ) : int|false

Stil procedural

intlcal_field_difference ( IntlCalendar $cal , float $when , int $field ) : int|false

Return the difference between the given time and the time this object is set to, with respect to the quantity specified the field parameter.

This method is meant to be called successively, first with the most significant field of interest down to the least significant field. To this end, as a side effect, this calendarʼs value for the field specified is advanced by the amount returned.



The IntlCalendar resource.


The time against which to compare the quantity represented by the field. For the result to be positive, the time given for this parameter must be ahead of the time of the object the method is being invoked on.


The field that represents the quantity being compared.

Una din constantele de câmp dată/oră ale IntlCalendar. Acestea sunt valori întregi de la 0 până la IntlCalendar::FIELD_COUNT.

Valorile întoarse

Returns a (signed) difference of time in the unit associated with the specified field sau false în cazul eșecului.


Example #1 IntlCalendar::fieldDifference()


$cal1 IntlCalendar::fromDateTime('2012-02-29 09:00:11');
$cal2 IntlCalendar::fromDateTime('2013-03-01 09:19:29');
$time $cal2->getTime();

"Time before: "IntlDateFormatter::formatObject($cal1), "\n";

"The difference in time is %d year(s), %d month(s), "
"%d day(s), %d hour(s) and %d minute(s)\n",

//now it was advanced to the target time, exception for the seconds,
//for which we did not measure the difference
echo "Time after: "IntlDateFormatter::formatObject($cal1), "\n";

Exemplul de mai sus va afișa:

Time before: 29 févr. 2012 09:00:11
The difference in time is 1 year(s), 0 month(s), 1 day(s), 0 hour(s) and 19 minute(s)
Time after: 1 mars 2013 09:19:11

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top