PHP | IntlCalendar roll() Function
Last Updated :
05 May, 2021
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 not carry into more significant fields.
Syntax:
bool IntlCalendar::roll( int $field, mixed $amountOrUpOrDown )
bool intlcal_roll( IntlCalendar $cal, int $field, mixed $amountOrUpOrDown )
Parameters:
- $cal: This parameter holds the resource of IntlCalendar object.
- $field: This parameter holds one of the IntlCalendar date/time field constants. The value of field constants are integer and lies between 0 to IntlCalendar::FIELD_COUNT.
- $amountOrUpOrDown: This parameter holds the signed amount to add to the field. The TRUE value represents rolling up (adding 1) and FALSE value represents rolling down (subtracting 1) from the DateTime field.
Return Value: This function returns TRUE on success or FALSE on failure.
Below program illustrates the IntlCalendar::roll() function in PHP:
Program:
php
<?php
ini_set ( 'date.timezone' , 'Asia/Calcutta' );
$calendar = IntlCalendar::createInstance( 'Asia/Calcutta' );
$calendar ->set(2019, 8, 24);
var_dump(IntlDateFormatter::formatObject( $calendar ));
$calendar ->roll(IntlCalendar::FIELD_DAY_OF_MONTH, false);
var_dump(IntlDateFormatter::formatObject( $calendar ));
?>
|
Output:
string(24) "Sep 24, 2019, 8:29:48 AM"
string(24) "Sep 23, 2019, 8:29:48 AM"
Reference: https://www.php.net/manual/en/intlcalendar.roll.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...