私の誕生日が過ぎたかどうかをチェックするウェブサイトを作りたいとしましょう。簡単にできます。
<?php
if( strtotime("2012-10-21") < time() ){
echo "Birthday has passed";
} else {
echo "Birthday hasn't passed";
}
?>
しかし、それは将来毎年ではなく、1 年間のことです。誰でもこれを行う方法を知っていますか?
<?php
if (strtotime("21 October")<time()) {
echo "Birthday has passed";
} else {
echo "Birthday hasn't passed";
}
?>
10月21日を過ぎるstrtotime()
と、現在の年のUNIXタイムスタンプが自動的に返されます。
を使用mktime
します。現在の年を使用するには、yearパラメータを空白のままにします。
if (mktime(1, 1, 1, 10, 21) < time()) {
...
}
PHPマニュアル:mktime
if(mktime(23, 59, 59, $birthdayDate, $birthdayMonth) < time())
{
//Birthday has passed
}
編集:私は23、59、59を使用したので、誕生日が過ぎたとは言われませんが、それでも誕生日です