我尝试使用格式Ymd
找出今天日期与特定日期之间的差异。
如何检查特定日期是否从今天起超过30天?
例如:
$date1 = '20160315'; // 2016-03-15
$date2 = '20160115'; // 2016-01-15
答案 0 :(得分:4)
试试这个
$date1=date_create('20160315');
$date2=date_create('20160115');
$diff=date_diff($date1,$date2);
$days = $diff->format("%a");
if($days > 30) do something
答案 1 :(得分:0)
这么简单......
$date1 = '20160315'; // 2016-03-15
$date2 = date(Ymd); // 2016-01-15
$day_difference = $date1 - $date2
if($day_difference > 30) {
echo 'specific day is greater than 30 days from today';
} else {
echo 'specific day is less than 30 days from today';
}
答案 2 :(得分:0)
试试这个:
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-11-13');
$interval = $datetime1->diff($datetime2);
$int = $interval->format('%R%a');
if($int > +30) {
echo "Greater than 30 days";
} else {
echo "Less than 30 days";
}