Thursday, October 9, 2025
HomeLanguagesPHP | IntlCalendar before() Function

PHP | IntlCalendar before() Function

The IntlCalendar::before() function is an inbuilt function in PHP which returns True if the object current time is before that of the passed object.

Syntax:

  • Object oriented style:
    bool IntlCalendar::before( IntlCalendar $other )
  • Procedural style:
    bool intlcal_before( IntlCalendar $cal, IntlCalendar $other )

Parameters:

  • $cal: This parameter holds the IntlCalendar resource.
  • $other: This parameter holds the calendar whose time checked against the primary object time.

Return Value: This function returns TRUE if the object current time is before that of the passed object.

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

Program:




<?php
  
// Create an IntlCalendar from a DateTime object or string
$calendar1 = IntlCalendar::fromDateTime('2019-08-29 09:19:29');
  
// Clone the Calendar date
$calendar2 = clone $calendar1;
  
// Use IntlCalendar::before() function
// and display result
var_dump($calendar1->before($calendar2));
var_dump($calendar2->before($calendar1));
  
// Use IntlCalendar::add() function to
// add month in date
$calendar1->add(IntlCalendar::FIELD_MONTH, 1);
  
// Use IntlCalendar::before() function
// and display result
var_dump($calendar1->before($calendar2));
var_dump($calendar2->before($calendar1));
          
?>


Output:

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

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

RELATED ARTICLES

Most Popular

Dominic
32348 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7095 POSTS0 COMMENTS
Thapelo Manthata
6791 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS