Related Articles

Related Articles

PHP | IntlCalendar equals() Function
  • Last Updated : 03 Sep, 2019

The IntlCalendar::equals() function is an inbuilt function in PHP which is used to compare two IntlCalendar time objects and returns true if this calendar and given calendar have same date otherwise returns false.

Syntax:

  • Object oriented style:
    bool IntlCalendar::equals( IntlCalendar $other )
  • Procedural style:
    bool intlcal_equals( IntlCalendar $cal, IntlCalendar $other )

Parameters:

  • $cal: This parameter holds the IntlCalendar resource.
  • $other: This parameter holds the calendar date and time to compare with the first time object.

Return Value: This function returns TRUE if the current time of both IntlCalendar object are same otherwise returns FALSE.

Below program illustrates the IntlCalendar::equals() function in PHP:



Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an IntlCalendar from a DateTime object or string
$calendar1 = IntlCalendar::fromDateTime('2019-03-21 09:19:29');
$calendar2 = IntlCalendar::fromDateTime('2018-03-21 09:19:29');
  
// Use IntlCalendar::equals() function to compare time
// of two IntlCalendar objects and display result
var_dump($calendar1->equals($calendar2));
  
// Clone the DateTime of $calendar1
$calendar2 = clone $calendar1;
  
// Use IntlCalendar::equals() function to compare time
// of two IntlCalendar objects and display result
var_dump($calendar1->equals($calendar2));
  
// Create an instance of IntlCalendar
$calendar2 = IntlCalendar::createInstance(NULL, 'en_US');
  
// Set DateTime of $calendar2 to $calendar1
$calendar2->setTime($calendar1->getTime());
  
// Use IntlCalendar::equals() function to compare time
// of two IntlCalendar objects and display result
var_dump($calendar1->equals($calendar2));
  
// Clone the DateTime of $calendar1
$calendar2 = clone $calendar1;
  
// Set DateTime of $calendar2 to $calendar1
$calendar2->setTime($calendar1->getTime() - 10);
  
// Use IntlCalendar::equals() function to compare time
// of two IntlCalendar objects and display result
var_dump($calendar1->equals($calendar2));
  
?>

chevron_right


Output:

bool(false)
bool(true)
bool(true)
bool(false)

Reference: https://www.php.net/manual/en/intlcalendar.equals.php

My Personal Notes arrow_drop_up
Recommended Articles
Page :