No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

IntlCalendar::fieldDifference

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

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

Description

Object oriented style

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

Procedural style

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

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.

PHP: IntlCalendar::fieldDifference - Manual Home of Manuel PHP  Contents Haut

Parameters

cal

The IntlCalendar resource.

when

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.

field

The field that represents the quantity being compared.

One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

PHP: IntlCalendar::fieldDifference - Manual Home of Manuel PHP  Contents Haut

Return Values

Returns a (signed) difference of time in the unit associated with the specified field or FALSE on failure.

PHP: IntlCalendar::fieldDifference - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 IntlCalendar::fieldDifference()

<?php
ini_set
('date.timezone''Europe/Lisbon');
ini_set('intl.default_locale''fr_FR');

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

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

printf(
    
"The difference in time is %d year(s), %d month(s), "
  
"%d day(s), %d hour(s) and %d minute(s)\n",
    
$cal1->fieldDifference($timeIntlCalendar::FIELD_YEAR),
    
$cal1->fieldDifference($timeIntlCalendar::FIELD_MONTH),
    
$cal1->fieldDifference($timeIntlCalendar::FIELD_DAY_OF_MONTH),
    
$cal1->fieldDifference($timeIntlCalendar::FIELD_HOUR_OF_DAY),
    
$cal1->fieldDifference($timeIntlCalendar::FIELD_MINUTE)
);

//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";

The above example will output:

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

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-intlcalendar.fielddifference.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut