I need to use the indexed element as the amount to change the date by
$id = $_POST['id'];
$ids = explode(',',$id);
$dateCreated = date('Y-m-d');
$dateExpiredtemp =date_create($dateCreated);
date_modify($dateExpiredtemp,'+ $ids[2]');
$dateExpired = date('$dateExpiredtemp');
date_modify($dateExpiredtemp,'+ $ids[2]');
This line provides this error
Warning: date_modify(): Failed to parse time string (+ $ids[2]) at position 0 (+): Unexpected character in
$ids[2] is a string and it needs to be carried into the altering parameter of date_modify
Change this line of code
date_modify($dateExpiredtemp,'+ $ids[2]');
into
date_modify($dateExpiredtemp,'+ ' . $ids[2]);
Your initial code will not recognize the $ids[2]
since it is included in the string. Therefore, $ids[2]
won't be parsed.
There seems to be something wrong with your $ids
array.
I assume that $ids[2]
is just a number and that is why you're getting an error. You need to specify a unit of time such as days
. Take a look at the code below, I have added days
to the end of the 2nd parameter in the date_modify
function.
$id = $_POST['id'];
$ids = explode(',',$id);
$dateCreated = date('Y-m-d');
$dateExpiredtemp =date_create($dateCreated);
date_modify($dateExpiredtemp,'+ $ids[2] days');
$dateExpired = date('$dateExpiredtemp');