检查$date是否等于 0000-00-00 00:00:00
我想要一个逻辑,如果$due等于没有日期,那么我想要从2000开始的数据。我下面的代码不起作用。
if($due == '0000-00-00 00:00:00'){
$due = strtotime('2000-00-00 00:00:00');
}
我想要一个逻辑,如果$due等于没有日期,那么我想要从2000开始的数据。我下面的代码不起作用。
if($due == '0000-00-00 00:00:00'){
$due = strtotime('2000-00-00 00:00:00');
}
如果你将 strtotime() 存储在 $due 中,那么你也需要像这样比较它
if($due == strtotime('0000-00-00 00:00:00')){
$due = strtotime('2000-00-00 00:00:00');
}
或者,更简单地说
if($due == 0){
$due = strtotime('2000-00-00 00:00:00');
}
但是如果$due来自你的db作为字符串,你会想要strtotime()它:
$due = strtotime($due);
if($due == 0){
$due = strtotime('2000-00-00 00:00:00');
}
不过,请注意时区。也就是说,strtotime('0000-00-00 00:00:00 UTC') != strtotime('0000-00-00 00:00:00 EST')。这也可能打破你的比较。
我不知道为什么strtotime不能为我正常工作。可能是因为时区和其他东西。
一如既往,花哨的正则表达式就像一个魅力。我不知何故沉迷于它!
if(preg_match("/0{4}/" , $dbDateField))
{
// no its not acceptable
}
else
{
//ok
}