PHP | IntlCalendar add() Function Last Updated : 26 Sep, 2021 Comments Improve Suggest changes Like Article Like Report The IntlCalendar::add() function is an inbuilt function in PHP which is used to add a signed amount of time to a field. Syntax: Object oriented style: bool IntlCalendar::add( int $field, int $amount ) Procedural style: bool intlcal_add( IntlCalendar $cal, int $field, int $amount ) Parameters: $cal: This parameter holds the IntlCalendar resource.$field: This parameter holds the IntlCalendar date/time field constants. It holds the integer value lies between 0 to IntlCalendar::FIELD_COUNT.$amount: The signed amount to add to the current field. If the value of amount is positive then it will moved forward and if the value of amount is negative then it will moved into the past. Return Value: This function returns TRUE on success or FALSE on failure. Below programs illustrate the IntlCalendar::add() function in PHP:Program 1: php <?php // Create an IntlCalendar from a DateTime object or string $calendar = IntlCalendar::fromDateTime('2019-08-29 09:19:29'); // Add the date $calendar->add(IntlCalendar::FIELD_MONTH, 1); // Display the result date echo IntlDateFormatter::formatObject($calendar), "\n"; // Add the date $calendar->add(IntlCalendar::FIELD_WEEK_OF_MONTH, 1); // Display the result output echo IntlDateFormatter::formatObject($calendar); ?> Output: Sep 29, 2019, 9:19:29 AM Oct 6, 2019, 9:19:29 AM Program 2: php <?php // Create an IntlCalendar from a DateTime object or string $calendar = IntlCalendar::fromDateTime('2019-08-29 09:19:29'); // Add the date $calendar->add(IntlCalendar::FIELD_YEAR, 5); // Display the result date echo IntlDateFormatter::formatObject($calendar), "\n"; // Add the date $calendar->add(IntlCalendar::FIELD_YEAR, 10); // Display the result output echo IntlDateFormatter::formatObject($calendar), "\n"; // Add the date $calendar->add(IntlCalendar::FIELD_HOUR_OF_DAY, 10); // Display the result output echo IntlDateFormatter::formatObject($calendar); ?> Output: Aug 29, 2024, 9:19:29 AM Aug 29, 2034, 9:19:29 AM Aug 29, 2034, 7:19:29 PM Reference: https://www.php.net/manual/en/intlcalendar.add.php Comment More infoAdvertise with us Next Article PHP | IntlCalendar add() Function jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Intl Similar Reads PHP | IntlCalendar after() Function The IntlCalendar::after() function is an inbuilt function in PHP which returns True if the object time is after that of the passed object. Syntax: Object oriented style:bool IntlCalendar::after( IntlCalendar $other )Procedural style:bool intlcal_after( IntlCalendar $cal, IntlCalendar $other ) Parame 1 min read PHP | IntlCalendar equals() Function The IntlCalendar::equals() function is an inbuilt function in PHP which is used to compare two IntlCalendar time objects and returns true if this calendar and given calendar have same date otherwise returns false. Syntax: Object oriented style: bool IntlCalendar::equals( IntlCalendar $other ) Proced 2 min read PHP | IntlCalendar set() Function The IntlCalendar::set() function is an inbuilt function in PHP which is used to set the time field or several common fields at once. The range of field value depends on the calendar. This function can not be called with exactly four parameters. Syntax: Object oriented style bool IntlCalendar::set( i 2 min read PHP | IntlCalendar get() Function The IntlCalendar::get() function is an inbuilt function in PHP which is used to get the value for a specific field. Syntax: Object oriented style int IntlCalendar::get( int $field ) Procedural style int intlcal_get( IntlCalendar $cal, int $field ) Parameters: This function uses two parameters as men 2 min read PHP | IntlCalendar roll() Function The IntlCalendar::roll() function is an inbuilt function in PHP which is used to add value to field without carrying into more significant fields. The difference between IntlCalendar::roll() and IntlCalendar::add() function is that, the field value of IntlCalendar::roll() function overflow, it does 2 min read PHP | IntlCalendar before() Function The IntlCalendar::before() function is an inbuilt function in PHP which returns True if the object current time is before that of the passed object. Syntax: Object oriented style: bool IntlCalendar::before( IntlCalendar $other ) Procedural style: bool intlcal_before( IntlCalendar $cal, IntlCalendar 1 min read PHP | IntlCalendar isSet() Function The IntlCalendar::isSet() function is an inbuilt function in PHP which is used to check whether a given field is set or not. This function is opposite to IntlCalendar::clear() function. Syntax: Object oriented style bool IntlCalendar::isSet( int $field ) Procedural style bool intlcal_is_set( IntlCal 1 min read PHP | IntlCalendar::__construct() Function The IntlCalendar::__construct() function is an inbuilt function in PHP which is used to create a private constructor for disallowing instantiation. Syntax: private IntlCalendar::__construct( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return 1 min read PHP | IntlCalendar fromDateTime() Function The IntlCalendar::fromDateTime() function is an inbuilt function in PHP which is used to create an IntlCalendar from a DateTime object or string. The value of new calendar represents the same instant as the DateTime and timezone. Syntax: Object oriented style IntlCalendar IntlCalendar::fromDateTime( 2 min read PHP | IntlCalendar getTime() Function The IntlCalendar::getTime() function is an inbuilt function in PHP which is used to return the time currently represented by the object. The time is expressed in terms of milliseconds since the epoch. Syntax: Object oriented style float IntlCalendar::getTime( void ) Procedural style float intlcal_ge 1 min read Like