Saturday, May 30, 2026
HomeLanguagesPHP | IntlCalendar equals() Function

PHP | IntlCalendar equals() Function

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:




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


Output:

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

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

RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6893 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS