Php DateTime不工作:查看日期是否早于30天
由于某种原因,我还没有完全意识到,这是行不通的。如果发布文章的日期早于30天,我想防止某些事情发生,其中数据库中的Php DateTime不工作:查看日期是否早于30天,php,datetime,Php,Datetime,由于某种原因,我还没有完全意识到,这是行不通的。如果发布文章的日期早于30天,我想防止某些事情发生,其中数据库中的fetchData[“article_date”]是2015-09-08 15:18:27 $new = new DateTime(date('Y-m-d H:i:s')); $old = new DateTime($fetchData["article_date"]); if(strtotime($old->modify('+30 days') < $new))
fetchData[“article_date”]
是2015-09-08 15:18:27
$new = new DateTime(date('Y-m-d H:i:s'));
$old = new DateTime($fetchData["article_date"]);
if(strtotime($old->modify('+30 days') < $new)) {
// Older than 30 days
}
$new=newdatetime(日期('Y-m-dh:i:s');
$old=new DateTime($fetchData[“article_date”]);
如果(strotime($old->modify('+30天')<$new)){
//超过30天
}
非常感谢您的帮助。要知道发表文章的日期是否早于30天,您可以执行以下操作:
$new = new DateTime(date('Y-m-d H:i:s'));
$old = new DateTime($fetchData["article_date"]);
if($old->modify('+30 days')->getTimestamp() < $new->getTimestamp()) {
// older than 30 days
}
$new=newdatetime(日期('Y-m-dh:i:s');
$old=new DateTime($fetchData[“article_date”]);
如果($old->modify('+30天')->getTimestamp()<$new->getTimestamp()){
//超过30天
}
要知道发表文章的日期是否早于30天,可以执行以下操作:
$new = new DateTime(date('Y-m-d H:i:s'));
$old = new DateTime($fetchData["article_date"]);
if($old->modify('+30 days')->getTimestamp() < $new->getTimestamp()) {
// older than 30 days
}
$new=newdatetime(日期('Y-m-dh:i:s');
$old=new DateTime($fetchData[“article_date”]);
如果($old->modify('+30天')->getTimestamp()<$new->getTimestamp()){
//超过30天
}
只是一个例子
$new = new DateTime(date('Y-m-d H:i:s'));
$old = new DateTime('2015-12-22 15:18:27');
$interval = $old->diff($new);
if($interval->format('%a') > 30) {
}
只是一个例子
$new = new DateTime(date('Y-m-d H:i:s'));
$old = new DateTime('2015-12-22 15:18:27');
$interval = $old->diff($new);
if($interval->format('%a') > 30) {
}
如果条件不正确,您的
modify
函数生成一个对象,您可以直接将其与您的$new
进行比较,后者也是一个对象
$new = new DateTime(date('Y-m-d H:i:s'));
$old = new DateTime($fetchData["article_date"]);
if($old->modify('+30 days') < $new) {
echo "hello";
}
$new=newdatetime(日期('Y-m-dh:i:s');
$old=new DateTime($fetchData[“article_date”]);
如果($old->modify('+30天')<$new){
回音“你好”;
}
如果
条件错误,您的
modify
函数生成一个对象,您可以直接将其与您的$new
进行比较,后者也是一个对象
$new = new DateTime(date('Y-m-d H:i:s'));
$old = new DateTime($fetchData["article_date"]);
if($old->modify('+30 days') < $new) {
echo "hello";
}
$new=newdatetime(日期('Y-m-dh:i:s');
$old=new DateTime($fetchData[“article_date”]);
如果($old->modify('+30天')<$new){
回音“你好”;
}
嗯,$old->modify(“+30天”)<$new
返回一个布尔值,您如何strotime
返回一个布尔值?只需删除strotime
为什么要使用DateTime对象和标准unix时间戳日期函数进行混合选择。。。。使用DateTime diff()查找两个DateTime对象之间的差异,$old->modify(“+30天”)<$new
返回布尔值,如何strotime
返回布尔值?只需删除strotime为什么要使用DateTime对象和标准unix时间戳日期函数进行混合选择。。。。使用DateTime diff()查找两个DateTime之间的差异objects@P.Nick不客气。请接受答案,因为它解决了您的问题。:)@尼克,不客气。请接受答案,因为它解决了您的问题。:)