Calendar Functions in PHP: Part 2


Introduction

In this tutorial you will learn how to use PHP calendar functions. The PHP calendar functions are used to implement various types of calendar formats. Here I will explain some Calendar functions and I am also described some PHP calendar functions in PART 1.

PHP Calendar cal_to_jd  function

It converts a given date to Julian day count. The cal_to_jd calendar function  (GREGORIAN, JULIAN, JEWISH or FRENCH ) calendar are supported.

Syntax

cal_to_jd (calendar, month, day, year)


Parameters in cal_to_jd function

It has four parameters and every parameter is required in this function.
 

Parameter Description
calendar It specifies name of calendar.
month It specifies month number.
day It specifies day.
year It specifies year.


Example of cal_to_jd function
 

<?php

$days=cal_to_jd(CAL_GREGORIAN,12,21,2012);

echo"If date in GREGORIAN then Julian day count = ";

echo $days;

echo"</br>";

$days=cal_to_jd(CAL_JULIAN,12,21,2012);

echo"If date in JULIAN then Julian day count = ";

echo $days;

echo"</br>";

$days=cal_to_jd(CAL_JEWISH,12,21,2012);

echo"If date in JEWISH then Julian day count = ";

echo $days;
?>

Output

call-to-jd-calendar-function-in-php.jpg

PHP Calendar easter_date function

It returns the Unix timestamp for midnight on Easter of a given year. The easter_date function only accepts years between 1970 to 2037. If the year is outside of that range then the function will generate a warning.


Syntax
 

easter_date (year)


Parameters in easter_date function

Contains one parameter; it is:
 

Parameter Description
year Specifies the year to calculate.


Example of easter_date function:
 

<?php

echo (easter_date()."</br>");

echo(date("M-d-Y",easter_date(2000))."<br/>");

echo(date("M-d-Y",easter_date(2005))."<br/>");

echo(date("M-d-Y",easter_date(2007))."<br/>");
?>

Output

easter-date-calendar-function-in-php.jpg

PHP Calendar easter_days function

It returns the number of days after March 21 on which Easter falls for a given year. If in this function you do not specify a year then it assumes the current year.

Syntax
 

easter_days (year, month)


Parameters in easter_days function

It has two parameters and every parameter is optional in this function; they are:

 

Parameter Description
year It specifies the year to calculate the midnight on Easter from.
month It specifies month number.


Example of easter_days function:
 

<?php

echoeaster_days(2001)."<br/>";

echoeaster_days(2005)."<br/>";

echoeaster_days(2007)."<br/>";
?>

Output

easter-days-calendar-function-in-php.jpg


Similar Articles