在PHP中添加三个月的日期 [英] Adding three months to a date in PHP
本文介绍了在PHP中添加三个月的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为 $ effectiveDate
的变量,其中包含日期 2012-03-26 。
/ p>
这是我尝试过的:
$ effectiveDate = strtotime(+ 3个月,strtotime($ effectiveDate));
和
$ effectiveDate = strtotime(date(Ymd,strtotime($ effectiveDate))+3个月);
我做错了什么?
解决方案
更改为这将给您预期的格式:
$ effectiveDate = date('Ym-d',strtotime(+ 3 months,strtotime($ effectiveDate)));
I have a variable called $effectiveDate
containing the date 2012-03-26.
I am trying to add three months to this date and have been unsuccessful at it.
Here is what I have tried:
$effectiveDate = strtotime("+3 months", strtotime($effectiveDate));
and
$effectiveDate = strtotime(date("Y-m-d", strtotime($effectiveDate)) . "+3 months");
What am I doing wrong? Neither piece of code worked.
解决方案
Change it to this will give you the expected format:
$effectiveDate = date('Y-m-d', strtotime("+3 months", strtotime($effectiveDate)));
这篇关于在PHP中添加三个月的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文