ARTICLE
Calendar Function in PHP: Part 1
In this article I am going to explain the calendar functions in PHP.
Introduction
The PHP Calendar functions are for working with various calendar formats. Basically the calendar formats are based on Julian dates. Here I am going to explain some of PHP calendar functions.
PHP cal_days_in_month function
This function returns the number of days in a month of a given year and calendar.
Syntax
| cal_days_in_month (calendar, month, year) |
Parameters in cal_days_in_month function
It has three parameters and every parameter is required in this function.
| Parameter | Description |
| calendar | It specifies which type of calendar. |
| month | It specifies month number. |
| year | It specifies year. |
Example of cal_days_month function:
| <?php $daysval=cal_days_in_month(CAL_GREGORIAN,2,2016); echo("The $daysval days will be in Feb 2016"); ?> |
Output

PHP cal_from_jd function
It converts the given Julian day into date of the given calendar.
Syntax
| cal_from_jd (jday, calendar) |
Parameters in cal_from_jd function
It have two parameters and every parameter is required in this function.
| Parameter | Description |
| calendar | It specifies which type of calendar. |
| jday | It is used for count Julian days. |
Example of cal_from_jd function:
| <?php $d=unixtojd(mktime(0,0,0,1,10,2005)); echo"<pre>"; print_r (cal_from_jd($d,CAL_GREGORIAN)); ?> |
Output

PHP cal_info function
It returns the array that contains information about a given calendar.
Syntax
Parameters of the cal_info function
It has only one parameter.
| Parameter | Description |
| calendar | It specifies which type of calendar. In it 0 defines CAL_GREGORIAN. 1 defines CAL_JULIAN. 2 defines CAL_French. |
Example of cal_info function:
| <?php $calinfo=cal_info(0); echo"<pre>"; print_r($calinfo); ?> |
Output