Php 从格式化日期到变量的转换
echo按预期显示了5,但我现在如何将$diff转换为一个变量(如int),以便进行其他数值比较?在数值上下文中使用该变量时,大多数情况下PHP会自动转换为int。但是如果您想自己做,请使用Php 从格式化日期到变量的转换,php,Php,echo按预期显示了5,但我现在如何将$diff转换为一个变量(如int),以便进行其他数值比较?在数值上下文中使用该变量时,大多数情况下PHP会自动转换为int。但是如果您想自己做,请使用intval()函数 $now = date("Y-m-d H:i:s"); $date1=date_create($StartDate); $date2=date_create($now); $diff=date_diff($date1,$date2); echo $diff->format("%a
intval()
函数
$now = date("Y-m-d H:i:s");
$date1=date_create($StartDate);
$date2=date_create($now);
$diff=date_diff($date1,$date2);
echo $diff->format("%a"); //Difference in days, Es: 5
伟大的非常感谢。
$days_diff = intval($diff->format("%a"));