使用できますstrtotime()
:
$OldDate = "2011-09-30";
$oldDateUnix = strtotime($OldDate);
if(date("Y", $oldDateUnix) < date("Y")) {
echo "Year is less than current year";
} else {
echo "Year is greater than current year";
}
アップデート
型にはまらない日付スタンプを使用しているため、次のようなさまざまな方法を使用する必要があります。
$OldDate = "09-30-2011";
list($month, $day, $year) = explode("-", $OldDate);
$oldDateUnix = strtotime($year . "-" . $month . "-" . $day);
if(date("Y", $oldDateUnix) < date("Y")) {
echo "Year is less than current year";
} else {
echo "Year is greater than current year";
}
注:が日付を正しく認識できるよう常に確認したい場合は、 YYYY-MM-DDstrtotime
を使用してください。