Comparing Dates, Learning PHP

I’m learning a lot of PHP here recently. I’ve never programmed in it before, but it is a fun little language. The nuances of the syntax are interesting sometimes – very typo prone! I’ve found several sites invaluable in getting the hang of the syntax, but I only recently thought to put them in here. If I find more, I’ll add them in later!

#1: I’ve referenced w3schools a lot over the years for a lot of different langues. It is a fantastic site for basic reference.

The useful site that spawned this post is actually where I found a simple method for comparing dates utilizing the strtotime function. I love how he did it “the hard way” first. That is totally how I was planning on doing it, and why I was searching for an easier way!

Reading the post is worthwhile, but sometimes I just want to skip to the code. The following is a sample of the code I wrote based on Mike D’Agostino’s helpful writing.

$regopen = 0;
//convert dates to comparable formats
$date1 = strtotime($startdate);
$date2 = strtotime($earlydate);
$date3 = strtotime($enddate);
$today = strtotime($todaydate);
//now to compare - it's so easy its beautiful
If (($today >= $date1) AND ($today <= $date3)) {
$regopen = 1;
   //early pricing or regular?
$cost = $costreg;
If ($today <= $date2) $cost = $costearly;

Leave a Reply