I have a form with the input type date. Now, I want to get the selected date from the form, add 30 day's and save to my MySQL database. Here is an example.
I want from this --> 2014-06-20
too this one --> 2014-07-20 (+30days)
Here is my HTML:
<label for ="lb_Date">Select your Date </label>
<input type="date" class="form-control" id="DateInput" name="date"placeholder="" required>
Here is my PHP
$date = $_POST['date'];
$newDate = new DateTime('$date');
$newDate->modify('+30 day');
echo $date->format('YY-mm-dd');
The echo
gives me the right result, but the error message doesn't allow to save $newDate in my MySQL database.
The Error Message:
Catchable fatal error: Object of class DateTime could not be converted to string enter code here...
What's wrong? Why I need to convert something, the output is just right for MySQL. I don't understand.