我正在尝试从这一天的日期中减去发布日期。
$subs_date = $_POST['pv']; // user gives how many dates he wants to subtract
$date = (date("Y-m-d"));
$new_date = strtotime ( '-'.$subs_date.'day' , strtotime ( $date ) ) ;
echo $new_date;
这给了我结果:1353884400
怎么了?
您可以使用 DateTime->sub() http://www.php.net/manual/de/datetime.sub.php
<?php
$date = new DateTime();
$date->sub(new DateInterval('P' . $_POST['pv'] . 'D'));
echo $date->format('Y-m-d') . "\n";
?>
假设您的代码有效,您可以执行以下操作:
$subs_date = $_POST['pv']; // user gives how many dates he wants to substract
$date = (date("Y-m-d"));
$new_date = strtotime ( '-'.$subs_date.'day' , strtotime ( $date ) ) ;
//add this:
$new_date = date('m-d-Y', $new_date);
echo $new_date;