4
I am assigning today’s date in a variable, I would like to know how to assign today’s date plus 60 days. How would the syntax ?
$dateIni = date('Y-m-d');
4
I am assigning today’s date in a variable, I would like to know how to assign today’s date plus 60 days. How would the syntax ?
$dateIni = date('Y-m-d');
6
You can pass a second argument to date
to specify the date, through a timestamp. In this case, we will use strtotime
to facilitate the service (this function creates a string-based timestamp that represents the desired amount of time).
$dateIni = date('Y-m-d', strtotime('+60 days'));
It is also possible to do through the class DateTime
- which I always prefer to use.
Behold:
$date = new DateTime('+60 days');
echo $date->format('Y-m-d');
If you are using PHP 5.4 >=, you can still do so:
echo (new DateTime('+60 days')->format('Y-m-d');
To fix the knowledge about dates in PHP, I’ll link some important questions on the subject:
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.