Web production note

 【更新日 :

【PHP】strtotimeで日付を比較する

Category:
PHP

strtotimeで日付を比較するサンプルコードです。

//現在の日付けを取得
$today = date("Y/m/d");

//比較する日付けの設定
$target_day = "2016/07/01";

//日付けを比較
if(strtotime($today) === strtotime($target_day)) {
	//$todayが今日の場合
}

if(strtotime($today) > strtotime($target_day)) {
	//$todayが過去の場合
}

if(strtotime($today) < strtotime($target_day)) {
	//$todayが未来の場合
}

参考リンク