我正在尝试从当天的日期中减去过帐日期。
$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
怎么了?
答案 0 :(得分:3)
您可以使用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";
?>
答案 1 :(得分:1)
假设您的代码有效,您可以执行以下操作:
$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;