I’ve written about date manipulation in PHP before. There are some truly horrible hacks out there. Today I needed to detect whether a given year was a leap year, in order to write future-proof code for a calendar. PHP has got to have a way of doing this. I Googled and found this. And this, which is almost as bad. Urgh. Sorry, but that is one of those occasions when the coder should have asked him/herself if there wasn’t a better way, and at least considered looking at the manual for the date function. There is of course a quick and simple way. Here it is.
So I wrote one line of code:
$maxfebday = date('L', strtotime("$currentyear-01-01")) ? 29 : 28;