在PHP中添加三个月的日期

编程入门 行业动态 更新时间:2024-10-23 15:34:04
本文介绍了在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中添加三个月的日期

本文发布于:2023-10-16 00:21:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1495915.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!