![](/img/trans.png)
[英]How to generate dynamic expiry dates like 3 months, 6 months, 9 months and 12 months from the today date in php
[英]PHP date from today to 4 months
有谁知道为什么它一直显示日期01-05-70?
$effectiveDate = strtotime("+4 months", strtotime($effectiveDate)); // returns timestamp
echo date('d-m-y',$effectiveDate); // formatted version
我希望它打印今天的日期+ 4个月。
在您的代码中, $effectiveDate
包含无效日期。 因此strtotime()
返回1970年1月1日的unix纪元。
但是,如果您只需要四个月后的日期,则根本不需要该变量。
echo date('d-m-y',strtotime('+4 months'));
$today = date('d-m-y');
$monthsFour = date('d-m-y',strtotime("+4 months"));
echo $today;
echo "<br>";
echo $monthsFour;
您在评论中的问题: Do you know how I express the year as 2016 as opposed to 16?
将日期函数中的y
替换为大写的Y
编辑:
$today = date('d-m-Y');
$monthsFour = date('d-m-Y',strtotime("+4 months"));
echo $today;
echo "<br>";
echo $monthsFour;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.