drktvjp713333 2018-11-03 14:07 采纳率: 0%
浏览 50
已采纳

PHP如果条件与日期wordpress小部件

I have a date of updated posts $date which is printing the date as "November 3, 2018"

And I have a widget that should be shown only if the date is before October 29, 2018

I thave ried something like this for example:

$date    = get_the_time( 'F j, Y', $ID );
$deadline = strtotime('2018-10-29');
if ($date > $deadline) {
    echo 'Yes';
} else {
    echo 'No';
}
  • 写回答

1条回答 默认 最新

  • douqian6315 2018-11-03 14:50
    关注

    you have to format the date as "Y-m-d" so :

    $date    = get_the_time( "Y-m-d");
    //var_dump(  strtotime($date));
    $deadline = strtotime('2010-09-29');
    //var_dump( $deadline);
    if (strtotime($date) > $deadline) {
      echo 'Yes';
    } else {
    echo 'No';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?