wordpress - PHP Compare date to current date does not work -
this wordpress site dates custom , not post dates. i'm trying compare expire date current date. works on dates when expire date on 01/01/2017 or 01/01/2016 returns invalid status. when date on year 2017 still returns invalid status. somehow not consistent , not sure check , statement might missing. sample code. expired date stored in $dates[1] , value has format of mm/dd/yy. used wordpress current_time code call 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"; } ?>
i figured out. format of date, year of date had problem. though changing format way. altered using explode on php separates date format if using '/' , assign array. compare current year year of expire date.
<?php $expire_year = explode('/', $dates[1]); if ($dates[1] < date('m/d/y', strtotime($current_date_test))){ if($expire_year[2] > date('y', strtotime($current_date_test))){ echo '<td class="-status"><span>valid</span></td>'."\n"; } else{ echo '<td class="-status"><span>invalid</span></td>'."\n"; } else{ if ($dates[1] >= date('m/d/y', strtotime($current_date_test)) ){ echo '<td class="-status"><span>valid</span></td>'."\n"; } } ?>
thanks idea!
Comments
Post a Comment