我已将用户的生日保存在birthday1999-02-26.
我怎样才能检查今天的生日是否如此?
if(date('m-d') == ..?
Run Code Online (Sandbox Code Playgroud)
Pow*_*ord 11
这个答案应该有效,但这取决于strtotime能够找出数据库的日期格式:
$birthDate = '1999-02-26'; // Read this from the DB instead
$time = strtotime($birthDate);
if(date('m-d') == date('m-d', $time)) {
// They're the same!
}
Run Code Online (Sandbox Code Playgroud)
if(date('m-d') == substr($birthday,5,5))
Run Code Online (Sandbox Code Playgroud)
添加Tim说的话:
if(date('m-d') == substr($birthday,5,5) or (date('y')%4 <> 0 and substr($birthday,5,5)=='02-29' and date('m-d')=='02-28'))
Run Code Online (Sandbox Code Playgroud)