mercredi 1 juillet 2015

PHP Compare date to current date does not work

This is a wordpress site but the dates are custom and they are not post dates. I'm trying to compare an expire date to current date. It works on some dates but when expire date is on 01/01/2017 or 01/01/2016 it returns an Invalid status. Even when date is on the year 2017 it still returns invalid status. Somehow it is not consistent and I am not sure where to check and what statement might be missing. This is the sample code. Expired date is already stored in $dates[1] and the value has a format of MM/DD/YY. I used the wordpress current_time code to call the current date. Please help. Thanks!

<?php 
$current_datetime = current_time( 'mysql' );
if ($dates[1] < date('m/d/Y', strtotime($current_datetime)) ){
    echo '<td class="-status"><span>Invalid</span></td>'."\n";
}
else
if ($dates[1]  >= date('m/d/Y', strtotime($current_datetime)) ){
    echo '<td class="-status"><span>Valid</span></td>'."\n";
    }   

?>  

Aucun commentaire:

Enregistrer un commentaire