所以我有一个在它的日期时间格式为Y-m-d H:i:s
其中的许多图像数组而且我希望找到图像的日期和当前日期之间的天数。这是我到现在为止的地方......并且我为每一个小改变都会遇到新的错误。如何查找两天之间的小时数?
$myDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $current_time);
$currentDate = $myDateTime->format('Y-m-d');
foreach($all_images as $key => $am){
$myDateTime1 = DateTime::createFromFormat('Y-m-d H:i:s', $am['datetime']);
$imageDate = $myDateTime1->format('Y-m-d');
$datediff=date_diff($currentDate,$imageDate);
echo $datediff;
}
我得到这个错误: Warning: date_diff() expects parameter 1 to be DateTimeInterface, string given
任何帮助,将不胜感激!非常感谢!
通常,如果您处理日期计算,最简单的方法是将两个日期转换为秒以来的时间,然后对它们进行比较。 – neuhaus
或者你可以减去你的两个时间戳,并将结果除以3600. – Jerodev
@Jerodev我做到了,但后来我得到零 – meagler