2017-02-09 31 views
0

檢查與PHP如果發佈日期更新日期不匹配返回指示內容的通知旗幟更新更新日期日期時間差異顯示「內容更新/修訂後的」通知與PHP

這是否會成爲一種解決方法?

function content_update_notice() { 

    $post_date = strtotime($row['postdate']); 
    $update_on = strtotime($row['updatedate']); 

    if($post_date != $updated_on) { 

     $alert = "Post has been updated on ".$update_on; 

    } else { } 
} 

但是,如果$ update_on比10天更早,那麼請刪除通知。

我該怎麼辦,並且我的功能是否有效?

enter image description here

+0

您嘗試/調查了什麼? –

回答

0

DateTime是處理日期的有效途徑。在這種情況下:

function content_update_notice ($row) { 
    $post_date = new DateTime($row['postdate']); 
    $update_on = new DateTime($row['updatedate']); 

    if ($post_date != $update_on) { 
     $difference = $post_date->diff($update_on); 

     if ($difference->d < 10) { 
      return 'Post has been updated on ' . $update_on->format('F jS, Y'); 
     } 
    } 
}