尝试在数据库中使用日期时间并为其添加可变天数,然后找出旧日期和新日期之间的差异并显示它。我引用了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回音输出为0天0小时0分钟
应该是170天##小时##分钟 我尝试了手册中的几种方法,请不要禁止我使用。
答案 0 :(得分:4)
$time111 = date_add($time1, ...);
将$time1
更改为新值,并将其分配给$time111
相反,做
$time1 = new DateTime($postdate);
$time2 = clone $time1;
$time111 = date_add($time2, date_interval_create_from_date_string(''.$timelength.' days'));