PHP | IntlCalendar isWeekend() Function

The IntlCalendar::isWeekend() function is an inbuilt function in PHP which is used to check whether a given date/time is in the weekend or not.

Syntax:

  • Object oriented style
    bool IntlCalendar::isWeekend( float $date = NULL )
  • Procedural style
    bool intlcal_is_weekend( IntlCalendar $cal, float $date = NULL )

Parameters: This function uses two parameters as mentioned above and described below:



  • $cal: This parameter holds the resource of IntlCalendar object.
  • $date: This parameter holds the optional timestamp which represents the number of milliseconds since the epoch, excluding leap seconds. If the value of this parameter is NULL then it uses the current time.

Return Value: This function returns the Boolean value which represents the given time occurs in a weekend or not.

Below program illustrates the IntlCalendar::isWeekend() 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');
  
// Check the given DateTime is weekend or not
var_dump($calendar->isWeekend());
  
// Set the DateTime to the object
$calendar->set(2019, 8, 29);
  
// Check the given DateTime is weekend or not
var_dump($calendar->isWeekend());
  
// Set the DateTime object
$calendar->isWeekend(strtotime('2019-09-22 12:30:00'));
  
// Check the given DateTime is weekend or not
var_dump($calendar->isWeekend());
  
?>

chevron_right


Output:

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

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.