根据输入的天数(例如,230,20或360或任何天数)在PHP中如何获取日期(例如2013-06-02)? [英] How to get Date(e.g like 2013-06-02) in the past based on input numbers of days (e.g like 230, 20 or 360 or whatever number of days) in PHP?

查看:115
本文介绍了根据输入的天数(例如,230,20或360或任何天数)在PHP中如何获取日期(例如2013-06-02)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据用户输入的天数来获取过去的日期。

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


例如用户输入45表示计算从今天(2015-09-06)
回到过去达到45天那么那个日期是
数字45?

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?

如何在PHP中实现这一点!

How to achieve this in PHP please!

提前谢谢。

推荐答案

<?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"));
?>

这篇关于根据输入的天数(例如,230,20或360或任何天数)在PHP中如何获取日期(例如2013-06-02)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆