0

So I am experiencing a really odd behaviour and any consultancy would be much appreciated.

$start_date = '02-07-2014';
$finish_date = '05-05-2014';

if($start_date < $finish_date'){
    return true;
}else{
    return false;
}

In this case true is returned. The only time false is returned is when the difference between the two days is not bigger than around two weeks.

Moreover, if the finish date is really bigger than start date, true is always returned.

Domas
  • 1,133
  • 4
  • 18
  • 46

1 Answers1

1

It would be better if you compare dates like below -

$start_date = date("Y-m-d",strtotime("02-07-2014"));
$end_date = date("Y-m-d",strtotime("05-05-2014"));

if($start_date < $finish_date){
    return true;
}else{
    return false;
}

In this way you would be comparing dates in YYYY-MM-DD format, and it would be accurate

Anik
  • 441
  • 4
  • 7
  • 1
    You could also use strtotime() or DateTime object - as suggested in the duplicate ticket. – mark Jul 01 '14 at 12:23