我将如何在 php 中按给定月份和年份计算未来几个月

Posted

技术标签:

【中文标题】我将如何在 php 中按给定月份和年份计算未来几个月【英文标题】:how will i take future months by the given month and year in php 【发布时间】:2015-09-21 07:32:16 【问题描述】:
 INSERT:<input type="text" name="my">
    no of months:<input type="text" name="noofmonths">
<input type="submit" name="sub" value="submit">

点击提交按钮后,我想要相应的未来月份/年份。

Eg:INSERT: Septemeber 2015;
no of months:4;

i want an o/p:January 2016;

另一个例子:

Eg:INSERT: December 2015;
no of months:2;

i want an o/p:February 2016;

【问题讨论】:

似乎是一个不错的项目。如果您在尝试实施时发现任何错误,请告诉我们,以便我们为您提供帮助! 不知道插入的sql查询。 看这里:dev.mysql.com/doc/refman/5.6/en/insert.html 【参考方案1】:

你可以试试这个代码

假设用户输入这个日期

$date = "20 September";  //Your spelling for September is wrong make sure user enter correct spelling

用户输入 4 个月

echo $effectiveDate = date('F Y', strtotime("+4 months", strtotime($date)));

【讨论】:

以上是关于我将如何在 php 中按给定月份和年份计算未来几个月的主要内容,如果未能解决你的问题,请参考以下文章