我需要将以下行转换为PHP,但不确定DATEADD()等效项以及如何显示参数。
这是对PHP进行了略微修改的IF ELSE语句的脚本:
if ($period == '1 month')
$finish = DATEADD(m, 1, $start);
else if ($period == '1 year')
$finish = DATEADD(yy, 1, $start);
else
$finish = DATEADD(d, 1, $start);
由于
答案 0 :(得分:0)
查看strtotime()。
<?php
$start = time(); // your time origin
$result = strtotime("+1 month", $start); // respects 28/30/31 days
$result = strtotime("next monday", $start); // getting silly…
- 编辑 -
如果你喜欢物体,你也可以给DateTime::add()一个镜头。不知道为什么这会比strtotime方法更好。
<?php
$start = new DateTime();
$start->add(new DateInterval("P1M")); // add 1 month