Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Add one week to a user defined date [duplicate]

Tags:

html

php

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.

like image 840
jarnold Avatar asked Mar 02 '15 10:03

jarnold


People also ask

How do I add 7 days to a date?

Just do: $date = strtotime("+7 day"); echo date('M d, Y', $date);

How can add days in date in PHP?

PHP date_add() Function $date=date_create("2013-03-15"); date_add($date,date_interval_create_from_date_string("40 days")); echo date_format($date,"Y-m-d");

How do you add a day in Strtotime?

echo date ( 'Y-m-d' , strtotime ( $Date . ' + 10 days' )); ?> Method 2: Using date_add() Function: The date_add() function is used to add days, months, years, hours, minutes and seconds.


1 Answers

You can use this:

$startdate = $_POST['start_date'];
$date_to_pay = date('Y/m/d',strtotime('+1 week',$startdate));
like image 146
Narendrasingh Sisodia Avatar answered Oct 04 '22 15:10

Narendrasingh Sisodia