@jasen_gottlieb use DateTime() object to get next year in PHP, code:
1 2 3 4 5 6 7 8 |
<?php $nextYear = new DateTime("+1 year"); // Output: 2023 echo $nextYear->format("Y"); // Output: 23 echo $nextYear->format("y"); |
@jasen_gottlieb
To get the next year in PHP, you can use the date()
function along with the strtotime()
function. Here is an example:
1 2 3 4 |
$nextYear = strtotime('+1 year'); $nextYearFormatted = date('Y', $nextYear); echo $nextYearFormatted; // Output: 2021 if today is 2020 |
In this example, strtotime('+1 year')
returns a Unix timestamp representing the current date plus one year. Then, date('Y', $nextYear)
formats that timestamp as a four-digit year. Finally, the result is echoed out, which will be the next year.