PHP | cal_days_in_month( ) Function

The cal_days_in_month( ) function in PHP is an inbuilt function which is used to return the number of days in a month for a specific year and according to a specific calendar such as Gregorian calendar, French calendar, Jewish calendar etc.

The cal_days_in_month() function takes three parameters which are the calendar, month and year and returns the number of days according to a specified month, year and calendar.

Syntax:



cal_days_in_month($calendar, $month, $year)

Parameters: The cal_days_in_month() function in PHP accepts three parameters as described below:

  1. $calendar: It specifies the calendar you want to consider such as French, Gregorian, Jewish etc.
  2. $month: It specifies the month in the calendar you have opted.
  3. $year: It specifies the year in the calendar you have opted.

Return Value: It returns the number of days according to a specified month, year and calendar.

Errors And Exception:

  1. The cal_days-in_month function gives wrong output when the date used is before 1550.
  2. The cal_days-in_month function gives wrong output for dates which were before the discovery of leap year.

Examples:

Input: cal_days_in_month(CAL_JEWISH, 2, 1966);
Output: 29
Explanation: February 1966 had 29 days.

Input: cal_days_in_month(CAL_GREGORIAN, 2, 2004);
Output: 29
Explanation: February 2004 had 29 days

Below programs illustrate the cal_days_in_month() function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Using cal_days_in_month() function to
// know the number of days in february, 1966
$days = cal_days_in_month(CAL_JEWISH, 2, 1966);
  
echo "February 1966 had $days days.<br>";
  
?>

chevron_right


Output:

February 1966 had 29 days.

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Using cal_days_in_month() function to
// know the number of days in february, 2004
$days = cal_days_in_month(CAL_GREGORIAN, 2, 2004);
  
echo "February 2004 had $days days";
  
?>

chevron_right


Output:

February 2004 had 29 days

Reference:
http://php.net/manual/en/function.cal-days-in-month.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

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.