Krish Krish - 3 months ago 15
PHP Question

Dynamically adding x number of days to a date in PHP

I have a scenario where I have to add x number if days to a variable containing date. This x will be dynamic and cannot be guessed.

Any suggestions on how I can implement this?

$ticket_created_on_date_time = '2016-08-31 09:55:01'
$in_between_days = 2;

Answer

You can use math and the strtotime function to get a date in the past/future. Something like:

strtotime($ticket_created_on_date_time) + (86400 * $in_between_days)

(86400 is one day in seconds) ....or

strtotime($ticket_created_on_date_time . '+ ' . $in_between_days . ' days')

Demo: https://eval.in/634187