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 valie 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 // 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); ?> |
chevron_right
filter_none
Output:
Sep 29, 2019, 9:19:29 AM Oct 6, 2019, 9:19:29 AM
Program 2:
<?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); ?> |
chevron_right
filter_none
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
Recommended Posts:
- PHP | IntlCalendar isWeekend() Function
- PHP | IntlCalendar roll() Function
- PHP | IntlCalendar set() Function
- PHP | IntlCalendar after() Function
- PHP | IntlCalendar before() Function
- PHP | IntlCalendar::__construct() Function
- PHP | IntlCalendar createInstance() Function
- PHP | IntlCalendar equals() Function
- PHP | IntlCalendar fieldDifference() Function
- PHP | IntlCalendar getActualMaximum() Function
- PHP | IntlCalendar get() Function
- PHP | IntlCalendar fromDateTime() Function
- PHP | IntlCalendar getAvailableLocales() Function
- PHP | IntlCalendar getActualMinimum() Function
- PHP | IntlCalendar getFirstDayOfWeek() Function
- PHP | IntlCalendar getErrorMessage() Function
- PHP | IntlCalendar getErrorCode() Function
- PHP | IntlCalendar setTimeZone() Function
- PHP | IntlCalendar setTime() Function
- PHP | IntlCalendar getType() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

