How to add 1 Year to Current Date in PHP
In this tutorial, we are going to learn about how to add 1 year to the Current Date in PHP with the help of examples.
Consider, we have following current date :
$currentDate = '2024-01-20'
After adding the 1 year to a current date it returns the output like this : “2025-01-20” .
Adding 1 year to a current date
To add 1 year to a current date in PHP, we can use the built-in date() function by passing the date format and unix timestamp of the future year.
The date() function takes the date format as a first argument and timestamp as an second argument then returns the formatted date string.
Here is an example:
$futureYear = date("Y-m-d", strtotime("+1 year"));
echo $futureYear;
Output:
2025-01-20
In the example above, we have passed the two arguments to a date() function. The first argument is date format "Y-m-d"
and the second argument is strtotime(“+1 year”) this function returns the unix timestamp by adding 1 year to the current date.
Adding 5 years to the current date
Similarly, we can also add 5 years to the current date in PHP, by using the date() function with date format and future year timestamp that is +5 years in our case.
Here is an example:
$futureYear = date("Y-m-d", strtotime("+5 years"));
echo $futureYear;
Output:
2029-01-20