Return to Snippet

Revision: 32902
at October 4, 2010 19:58 by stamba


Initial Code
// Get the dates 
$today = date("m/d/Y");
$datefrom = "10/01/2010";
$dateto = "10/12/2010";

// Convert dates to strings
$todaystring = strtotime($today);
$datefromstring = strtotime($datefrom);
$datetostring = strtotime($dateto);

// Compare the dates (check if today is between start and end dates)
if ($todaystring >= $datefromstring && $todaystring <= $datetostring) {
    // Do something if today is in between
    echo "Date is ok.";
} else {
    // Do something if it is not in between
    echo "Date is wrong.";
}

Initial URL


Initial Description


Initial Title
Compare dates using strtotime

Initial Tags
date

Initial Language
PHP