I need to compare two dates
d1= 12-11-01(YY-MM-DD) and d2=2008-05-02(YYYY-MM-DD)
comparison d2 <= d1
It is not working as per requirement
Here please note that I need to compare dates with different date formats.
I need to compare two dates
d1= 12-11-01(YY-MM-DD) and d2=2008-05-02(YYYY-MM-DD)
comparison d2 <= d1
It is not working as per requirement
Here please note that I need to compare dates with different date formats.
Try with:
$d1 = strtotime('12-11-01');
$d2 = strtotime('2008-05-02');
if ( $d2 <= $d1 ) {}
DateTime is better than strtotime()
because it can account for timezones and daylight savings time
$dt1 = new DateTime('12-11-01');
$dt2 = new DateTime('2008-05-02');
if ( $dt2 <= $dt1 ) {
}
Do this :
if(strtotime('12-11-01') <= strtotime('2008-05-02'))
{
// do your task here
}
You can use this code:
$d1 = strtotime($date1);
$d2 = strtotime($date2);
if($d2 <= $d1){
// $date2 is before $date1
}
Like below,
if(strtotime($date1) < strtotime($date2)) {
// do something
}
Research it further here