How to assign another 60 days on a date compared to today's date in PHP?

4

I'm assigning today's date in a variable, I'd like to know how do I assign today's date plus 60 days. What would the syntax look like?

$dateIni = date('Y-m-d');
    
asked by anonymous 28.06.2016 / 20:23

1 answer

6

You can pass a second argument to date to specify the date, through a timestamp. In this case, we will use strtotime to make the service easier (this function creates a timestamp based on a string that represents the amount of time you want).

$dateIni = date('Y-m-d', strtotime('+60 days'));

It is also possible to do this through the class DateTime - which I always prefer to use.

See:

$date = new DateTime('+60 days');

echo $date->format('Y-m-d');

If you are using PHP 5.4 > =, you can still do this:

 echo (new DateTime('+60 days')->format('Y-m-d');

To set knowledge about dates in PHP, I'll link some important questions on the subject:

28.06.2016 / 20:25