PHP | IntlCalendar set() Function Last Updated : 25 Sep, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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( int $field, int $value ) or bool IntlCalendar::set( int $year, int $month, int $dayOfMonth = NULL, int $hour = NULL, int $minute = NULL, int $second = NULL ) Procedural style bool intlcal_set( IntlCalendar $cal, int $field, int $value ) or bool intlcal_set( IntlCalendar $cal, int $year, int $month, int $dayOfMonth = NULL, int $hour = NULL, int $minute = NULL, int $second = NULL ) Parameters: This function accepts many parameters as mentioned above and described below: $cal: This parameter holds the resource of IntlCalendar object. $field: This parameter holds one of the IntlCalendar date/time field constants. The field constants are integer values lies between 0 to IntlCalendar::FIELD_COUNT. $value: This parameter holds the new value of the given field. $year: This parameter holds the new value for IntlCalendar::FIELD_YEAR field. $month: This parameter holds the new value for IntlCalendar::FIELD_MONTH field. $dayOfMonth: This parameter holds the new value for IntlCalendar::FIELD_DAY_OF_MONTH field. The sequence of month starts from zero i.e. 0 for January, 1 for February etc. $hour: This parameter holds the new value for IntlCalendar::FIELD_HOUR_OF_DAY field. $minute: This parameter holds the new value for IntlCalendar::FIELD_MINUTE field. $second: This parameter holds the new value for IntlCalendar::FIELD_SECOND field. Return Value: This function returns TRUE on success and FALSE on failure. Below program illustrates the IntlCalendar::set() function in PHP: Program: php <?php // Set the DateTime zone ini_set('date.timezone', 'Asia/Calcutta'); ini_set('date.timezone', 'UTC'); // Create an instance of IntlCalendar $calendar = IntlCalendar::createInstance('Asia/Calcutta'); // Set the DateTime object $calendar->set(2019, 8, 24); // Display the calendar object var_dump(IntlDateFormatter::formatObject($calendar)); // Declare a new IntlGregorianCalendar object $calendar = new IntlGregorianCalendar(2016, 8, 24); // Set the year field $calendar->set(IntlCalendar::FIELD_YEAR, 2018); // Display the calendar object var_dump(IntlDateFormatter::formatObject($calendar)); ?> Output: string(24) "Sep 24, 2019, 8:23:53 AM" string(25) "Sep 24, 2018, 12:00:00 AM" Reference: https://www.php.net/manual/en/intlcalendar.set.php Comment More infoAdvertise with us Next Article PHP | IntlCalendar set() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Intl Similar Reads PHP IntlCalendar setTime() Function PHP IntlCalendar::setTime() function is an inbuilt function in PHP which is used to set the calendar time object in terms of milliseconds since the epoch. The calendar time instant is represented by the float and its value should be an integer number of milliseconds since the epoch (1 Jan 1970 00:00 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 setTimeZone() Function The IntlCalendar::setTimeZone() function is an inbuilt function in PHP which is used to set the new timezone for this calendar. The time is represented in terms of object and it preserves to the detriment of the timezone field values. Syntax: Object oriented style bool IntlCalendar::setTimeZone( mix 2 min read PHP | IntlCalendar add() Function 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: 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 Like