PHP - 将一周添加到用户定义的日期 [英] PHP - Add one week to a user defined date
问题描述
这个问题很可能是重复的,但我正努力为我的问题找到一个准确的答案。
用户输入客户租金的起始日期(在上一页的表格上),那么它需要生成下一个日期(一周后)客户需要支付。例如:
$ start_date = $ _POST ['start_date'];
$ date_to_pay = ???
可以说用户在2015/03/02输入:
$ start_date =2015/03/02;
然后我希望日期支付等于一周后(2015/03/09) :
$ date_to_pay =2015/03/09;
一个人会怎么做?非常感谢。
您可以试试这个
$ start_date =2015/03/02;
$ date = strtotime($ start_date);
$ date = strtotime(+ 7 day,$ date);
echo date('Y / m / d',$ date);
There's more than likely going to be a duplicate for this question, but I'm struggling to find a precise answer for my problem.
The user enters a starting date for a client's rent (on a form on a previous page), then it needs to generate the next date (one week later) that the client is required to pay. For example:
$start_date = $_POST['start_date'];
$date_to_pay = ???
Lets say the user enters in 2015/03/02:
$start_date = "2015/03/02";
I then want the date to pay to be equal to a week later (2015/03/09):
$date_to_pay = "2015/03/09";
How would one go around doing this? Many thanks.
You can try this
$start_date = "2015/03/02";
$date = strtotime($start_date);
$date = strtotime("+7 day", $date);
echo date('Y/m/d', $date);
这篇关于PHP - 将一周添加到用户定义的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!