如何根据PHP中的输入天数(例如230,20或360或任何天数)获取日期(例如2013-06-02)?

I want to get the date in the past based on numbers of days that input by user.

e.g User entered 45 means calculate from the current day (2015-09-06) back to the past to reached 45 days then what is that date of the number 45?

How to achieve this in PHP please!

Thank you in advance.

<?php
echo date('Y-m-d', strtotime("-45 days"));
?>

If you are taking the number from user through form or taking the number from variable

<?php
$days = "26"; //OR
$days = $_POST["inputName"];
echo date('Y-m-d', strtotime("-".$days."days"));
?>

You can directly achieve it from MySQL DB:

SELECT DATE_SUB(date_field,INTERVAL 45 DAY) AS SubtractDate
FROM table_name;

Or

SELECT date(DATE_SUB(now(),INTERVAL 45 DAY)) SubtractDate;

Some thing like this should work. But, you should search the web before asking here. That's the basic ABCD of anything. Hope you do that next time.

<?php
     echo date('Y-m-d', strtotime('-45 days'));
?>

echo date('Y-m-d',strtotime('-45days'));

$date=date_create("2013-06-02");
date_sub($date,date_interval_create_from_date_string("45 days"));

Initialize date like above or as howerver you want it and then pass that date object to the date_sub() function as above.