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');
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');
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: