I want to get today's date + one year. How do I achieve this with PHP's date functions?
Asked
Active
Viewed 5.1k times
9 Answers
7
You can use strtotime
and date
$date = '2010-09-16';
echo date('Y-m-d', strtotime("+12 months $date"));
// 2011-09-16
On a sidenote: DateTime questions like this have been answered over and over again, so you could have found how to add to a date easily by using the search function.
7
From PHP's documentation:
<?php
$date = new DateTime($your_supposed_date);
$date->add(new DateInterval('P1Y'));
echo $date->format('Y-m-d') . "\n";
?>
Gordon's much cleaner version (Thank you!):
<?php
$date = new DateTime("+12 months $theDate");
echo $date->format('Y-m-d') . "\n";
?>

fabrik
- 14,094
- 8
- 55
- 71
-
2While correct and good, note that `DateTime::__construct` uses the same parsing mechanism as `strtotime`, so you can also do `$date = new DateTime("+12 months $theDate"); echo $date->format('Y-m-d') . "\n";` – Gordon Sep 16 '10 at 07:24
1
$Ad_year = 2015-10-20
<?php echo $Ad_year + 1?>
Result 2016

Abdifatah Abdilahi
- 59
- 3
- 9
-
@TobSpr, But it does. I don't know if it works until I try it. But it does attempt to answer the question. What am I missing ? – Rohit Gupta Oct 18 '15 at 00:19
1
The shortest version:
echo (int)date('Y') + 1;

Mariyo
- 486
- 7
- 15
-
2
-
If you want to be strict, you will get this error `Binary operation "+" between string and 1 results in an error.`: https://phpstan.org/r/9f0842d1-8097-4dfd-a986-010a6e85670b – Mariyo Sep 06 '19 at 07:38
0
You could use the new Datetime and Datetime_Intervall-classes introduced in the later PHP 5-versions.
I once posted an answer in this question. Maybe it helps you :)
The advantage is, that this classes also checks for leap-seconds and leap-years, timezones, etc.
0
Best and easy solution... You can change month or year or day.
date('Y-m-d',strtotime("+1 day +2months +1 year"));

Ersoy
- 8,816
- 6
- 34
- 48

atif shaikh
- 127
- 3
- 10
0
Below code also return next year from current date:
<?php echo date('Y', strtotime('+12 month'));>