我想从约会开始月份,这些日期是从数据库中获取的,所以有些日期是'0000-00-00'格式。
//例如我在下面给出了这个日期
$arr='0000-00-00';
$thismonth = date('m', strtotime($arr));
echo $thismonth;
//这里我期待00或null,但答案是11。
date永远不是'0000-00-00'或0或null,在日期函数中你永远不会输入错误值,所以检查
$arr='0000-00-00';
if($arr != '0000-00-00'){
$thismonth = date('m', strtotime($arr));
echo $thismonth;
}
else{
$thismonth = '00';
}