Print dates 15 days forward from a start date

Asked

Viewed 70 times

1

I have this code that I printed out the dates stipulating the beginning and the end between them:

How would I make the system calculate 15 days after the $dateStart?

For example:

If that was the starting date $dateStart=05/11/2018 the system already stipulated the final date adding the 15 days to stay $dateEnd=19/11/2018

//Star date
    $dateStart      = '05/11/2018';
    $dateStart      = implode('-', array_reverse(explode('/', substr($dateStart, 0, 10)))).substr($dateStart, 10);
    $dateStart      = new DateTime($dateStart);

    //End date
    $dateEnd        = '25/04/2013';
    $dateEnd        = implode('-', array_reverse(explode('/', substr($dateEnd, 0, 10)))).substr($dateEnd, 10);
    $dateEnd        = new DateTime($dateEnd);

    //Prints days according to the interval
    $dateRange = array();
    while($dateStart <= $dateEnd){
        $dateRange[] = $dateStart->format('Y-m-d');
        $dateStart = $dateStart->modify('+1day');
    }
 foreach ($dateRange as $value) {

     echo $value;
 }

1 answer

1


With strtotime you can add whatever you want, see example below:

$data = "20-10-2014"; 
echo date('d/m/Y', strtotime("+2 days",strtotime($data)));

This example was taken from another post on the subject: Add days to a date

Browser other questions tagged

You are not signed in. Login or sign up in order to post.