在PHP中向$ Date添加天数 [英] Adding days to $Date in PHP

查看:123
本文介绍了在PHP中向$ Date添加天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以2010-09-17

我想将变量$ Date2设置为$ Date5,如下所示:

I would like to set the variables $Date2 to $Date5 as follows:

$Date2 = $Date + 1

$Date3 = $Date + 2

等.

,以便它返回2010-09-182010-09-19等...

so that it returns 2010-09-18, 2010-09-19 etc...

我尝试过

date('Y-m-d', strtotime($Date. ' + 1 day'))

但是这给了我$Date之前的日期.

but this gives me the date BEFORE $Date.

以"Y-m-d"格式获取日期以便在其他查询中使用的正确方法是什么?

What is the correct way to get my Dates in the format form 'Y-m-d' so that they may be used in another query?

推荐答案

您要做的就是使用days而不是day

All you have to do is use days instead of day like this:

<?php
$Date = "2010-09-17";
echo date('Y-m-d', strtotime($Date. ' + 1 days'));
echo date('Y-m-d', strtotime($Date. ' + 2 days'));
?>

它正确输出:

2010-09-18
2010-09-19

这篇关于在PHP中向$ Date添加天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆