2012-08-14 71 views
1

说我想要做一个网站,如果我的生日已经通过了检查,我可以很容易做到如何判断假期是否已过(每年)?

<?php 
if(strtotime("2012-10-21") < time()){ 
    echo "Birthday has passed"; 
    } else { 
     echo "Birthday hasn't passed"; 
    } 
?> 

但是,这只会在今后每年都没有占到一年。 任何人都知道如何做到这一点?

回答

2
<?php 
    if (strtotime("21 October")<time()) { 
     echo "Birthday has passed"; 
    } else { 
     echo "Birthday hasn't passed"; 
    } 
?> 

刚好路过10月21日至自动strtotime()返回UNIX时间戳当前年份。

+0

啊,没有意识到那很容易。谢谢! – Alice 2012-08-14 02:04:21

-1

PHP手册:mktime

if(mktime(23, 59, 59, $birthdayDate, $birthdayMonth) < time()) 
{ 
    //Birthday has passed 
} 

编辑:我用23,59,59,所以它不会说的生日已经过了,而它仍然是生日

相关问题