How to compare two dates in php if dates are in format \'03_01_12\'
and \'31_12_11\'
.
I am using this code:
$date1=date(\'
I know this is late, but for future reference, put the date format into a recognised format by using str_replace then your function will work. (replace the underscore with a dash)
//change the format to dashes instead of underscores, then get the timestamp
$date1 = strtotime(str_replace("_", "-",$date1));
$date2 = strtotime(str_replace("_", "-",$date2));
//compare the dates
if($date1 < $date2){
//convert the date back to underscore format if needed when printing it out.
echo '1 is small='.$date1.','.date('d_m_y',$date1);
}else{
echo '2 is small='.$date2.','.date('d_m_y',$date2);
}