Open In App

PHP | cal_days_in_month()

Improve
Improve
Like Article
Like
Save
Share
Report

cal_days_in_month() is an inbuilt function which returns the number of days in a particular month of a specified calendar. We have to pass calendar type, month and year as the parameter and the function will return the number of days in that month of the specified year of the calendar.
Syntax  

int cal_days_in_month ( int $calendar, int $month, int $year )

Parameters :  

  • Calendar : Calendar type to use for calculation. This value is required.
  • Month : Month in the selected calendar. This value is required.
  • Year : Year in the selected calendar. This value is required too.

Below is  the list of possible values that ‘calendar’ parameter can hold : 

  • CAL_GREGORIAN
  • CAL_JULIAN
  • CAL_JEWISH
  • CAL_FRENCH
  • CAL_NUM_CALS
  • CAL_DOW_DAYNO
  • CAL_DOW_SHORT
  • CAL_DOW_LONG
  • CAL_MONTH_GREGORIAN_SHORT
  • CAL_MONTH_GREGORIAN_LONG
  • CAL_MONTH_JULIAN_SHORT
  • CAL_MONTH_JULIAN_LONG
  • CAL_MONTH_JEWISH
  • CAL_MONTH_FRENCH
  • CAL_EASTER_DEFAULT
  • CAL_EASTER_ROMAN
  • CAL_EASTER_ALWAYS_GREGORIAN
  • CAL_EASTER_ALWAYS_JULIAN
  • CAL_JEWISH_ADD_ALAFIM_GERESH
  • CAL_JEWISH_ADD_ALAFIM
  • CAL_JEWISH_ADD_GERESHAYIM

Return Value : Returns the number of days in the month of the year for the specified calendar. 

php




<!DOCTYPE html>
<html>
<body>
 
<?php
$d = cal_days_in_month(CAL_GREGORIAN, 2, 1965); // Calendar Type - Gregorian
echo "There was $d days in February 1965.<br>";
 
$d = cal_days_in_month(CAL_GREGORIAN, 2, 2004); // Calendar Type - Gregorian
echo "There was $d days in February 2004.";
?>
</body>
</html>


Output : 

There was 28 days in February 1965.
There was 29 days in February 2004.

Last Updated : 31 May, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads