WAY2WEB: Web Design & business...


PHP: Easter_Date (Get the Date of Easter)

There are some functions in PHP which you use on a regular day-to-day basis, and I'm sure you can remember them. Easter_date is not one of them! This function is not quite as useful, but I'm sure it can be handy in certain circumstances.

Here's some example code to see what it does. Check it out:

<?php
$year = 2008; //The year to find the date of easter for
$unixyear = easter_date($year);
$easterday = date("l j F", $unixyear);
echo
'In the year '.$year.', Easter will be held on '.$easterday;
?>

The code is fairly self-explanatory, but I'll run through it anyway. The main function here is of course easter_date - this takes a numeric representation of a year as input (e.g. "2008"), and return a UNIX date string for the date of easter.

From this string, we have to translate it into a human readable format. We do this with the date() function, which takes the UNIX string and translates it into our format of choice (in this case it is "l j F").

There you go! A insight into the function which is easter_date. Hopefully you can find some creative uses for it.