Related Articles

Related Articles

PHP | IntlCalendar roll() Function
  • Last Updated : 25 Sep, 2019

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 carray 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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
Recommended Articles
Page :