Open In App

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 not carry into more significant fields.
Syntax: 
 

bool IntlCalendar::roll( int $field, mixed $amountOrUpOrDown )
bool intlcal_roll( IntlCalendar $cal, int $field, mixed $amountOrUpOrDown )

Parameters: 
 



Return Value: This function returns TRUE on success or FALSE on failure. 
Below program illustrates the IntlCalendar::roll() function in PHP:
Program: 
 




<?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
 

Article Tags :