本文介绍了在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中添加三个月的日期
发布评论