I have a form which lets the user select the start date of a an event and the number of days it will run for. The following is my PHP code:
$strt_date = mysqli_real_escape_string($con, $_POST['strt_date']);
$strt_date = date("d-m-Y", strtotime($strt_date));
$days = mysqli_real_escape_string($con, $_POST['days']);
$end_date = date_add($strt_date, date_interval_create_from_date_string("$days days"));
However, when I test it, I get the following Warning:
date_add() expects parameter 1 to be DateTime, string given in C:\wamp\www\filname...
So I followed Converting String to date and Datetime and altered my code to...
$strt_date = strtotime(mysqli_real_escape_string($con, $_POST['strt_date']));
$strt_date = date("d-m-Y", $strt_date);
$days = mysqli_real_escape_string($con, $_POST['days']);
$end_date = date_add($strt_date, date_interval_create_from_date_string("$days days"));
However this still didn't resolve the issue. What am I doing wrong?