[英]php datetime difference between datetime and datetime+int days
Trying to use the datetime in database and add a variable amount of days to it, then find the difference between the old date and new date and display it. 尝试在数据库中使用datetime并向其中添加可变的天数,然后查找旧日期和新日期之间的差异并显示它。 I've reference http://php.net/manual/en/datetime.add.php and 我参考了http://php.net/manual/en/datetime.add.php和
$postdate = $row["dated"]; // db value(datetime) assume 2016-04-12 18:35:00
$timelength = $row["timelength"]; // db value(int) assume 180
//Start decode and organizing
$time1 = new DateTime($postdate);
$time111 = date_add($time1, date_interval_create_from_date_string(''.$timelength.' days'));
$time211 = $time111->diff($time1);
$time222 = $time211->format('%d days %h hours %i minutes');
$time222 echo output is 0 days 0 hours 0 minutes $ time222 echo输出为0天0小时0分钟
It should be 170 days ## hours ## minutes I tried several approaches from the manual, Please don't ban me from SO. 我应该尝试使用手册中的几种方法,应该是170天##小时##分钟,请不要禁止我这样做。
$time111 = date_add($time1, ...);
changes $time1
to the new value as well as assigning it to $time111
将$time1
更改$time1
新值,并将其分配给$time111
Instead, do 相反,做
$time1 = new DateTime($postdate);
$time2 = clone $time1;
$time111 = date_add($time2, date_interval_create_from_date_string(''.$timelength.' days'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.