Tuesday, November 19, 2024
Google search engine
HomeLanguagesPHP | cal_days_in_month( ) Function

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:




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


Output:

February 1966 had 29 days.

Program 2:




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


Output:

February 2004 had 29 days

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

RELATED ARTICLES

Most Popular

Recent Comments