Code Snippet: Compare Date in PHP

Here’s a quick way of comparing two different dates on PHP. This is usually used in rental systems to determine over dues.

PHP Programming


< ?php

$endDate = "2009-11-25";
$curDate = date('Y-m-d',strtotime("Now"));

if ($curDate > $dueDate){
  print date('M d, Y', strtotime($curDate)) . ' is greater than '. date('M d, Y', strtotime($endDate))."\n\n";

} else {

   print date('M d, Y', strtotime($endDate)) . ' is greater than ' . date('M d, Y', strtotime($curDate))."\n\n";
}

?>


Permalink • Print • Comment

Trackback uri

http://seoroot.com/blog/computing/programming/php/compare-date-in-php.html/trackback

Related Entries

Leave a Comment