Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | IntlCalendar roll() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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: 
 

  • Object oriented style 
     
bool IntlCalendar::roll( int $field, mixed $amountOrUpOrDown )
  • Procedural style 
     
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
 
// Set the DateTime zone
ini_set('date.timezone', 'Asia/Calcutta');
 
// Create an instance of IntlCalendar
$calendar = IntlCalendar::createInstance('Asia/Calcutta');
 
// Set the DateTime to the calendar object
$calendar->set(2019, 8, 24);
 
// Display the calendar object
var_dump(IntlDateFormatter::formatObject($calendar));
 
// Roll down 1 day of date field
$calendar->roll(IntlCalendar::FIELD_DAY_OF_MONTH, false);
 
// Display the calendar object
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
 

My Personal Notes arrow_drop_up
Last Updated : 05 May, 2021
Like Article
Save Article
Similar Reads
Related Tutorials