This question already has answers here:
Closed 5 years ago.
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);
Please try the following:
date('d.m.Y', strtotime('+1 week', strtotime($start_date)));
Object Oriented Style using DateTime
classes:
$start_date = DateTime::createFromFormat('Y/m/d', $_POST['start_date']);
$one_week = DateInterval::createFromDateString('1 week');
$start_date->add($one_week);
$date_to_pay = $start_date->format('Y/m/d');
Or for those who like to have it all in one go:
$date_to_pay = DateTime::createFromFormat('Y/m/d',$_POST['start_date'])
->add(DateInterval::createFromDateString('1 week'))
->format('Y/m/d');
$start_date = "2015/03/02";
$new_date= date("Y/m/d", strtotime("$start_date +1 week"));
You can use this:
$startdate = $_POST['start_date'];
$date_to_pay = date('Y/m/d',strtotime('+1 week',$startdate));