PHP: Get next year’s date.

Last week, I wrote a short guide on how to get the current year in PHP. Today, I am going to show you how to get next year’s date using PHP.

Let’s start with the following example:

In the PHP code above, we:

  1. Created a new DateTime object.
  2. Afterwards, we provided the DateTime::add function with a DateInterval of P1Y. If we wanted to get a date that is 5 years into the future, we would have used P5Y as the interval instead.
  3. Finally, we retrieved the date in a YYYY-MM-DD format and did a var_dump on the result.

When I ran the above piece of code on the 14th of December, 2019, the result was: 2020-12-14

Note that if just want next year without the month or the day, then you can simply omit the “m” and “d” format characters:

This will result in “2020” being printed out.

If you want to get next year’s date using PHP’s date and strtotime functions, then you can try the following example:

As you can see, we were able to pass in “+1 year” as a parameter to PHP’s strtotime function. The result of strtotime provided the date function with a Unix timestamp of next year’s date.

Related articles that you might find helpful:

Facebook Comments