1

我正在尝试从这一天的日期中减去发布日期。

$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

怎么了?

4

2 回答 2

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";
?>
于 2012-11-28T17:35:43.947 回答
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;
于 2012-11-28T17:34:54.963 回答