26

I want to get today's date + one year. How do I achieve this with PHP's date functions?

daker
  • 3,430
  • 3
  • 41
  • 55
Testadmin
  • 2,880
  • 9
  • 49
  • 71
  • 1
    possible duplicate of [how do i display a date by adding a few months to it](http://stackoverflow.com/questions/3722442/how-do-i-display-a-date-by-adding-a-few-months-to-it) – Gordon Sep 16 '10 at 07:15

9 Answers9

80
echo date('Y', strtotime('+1 year'));
gianebao
  • 17,718
  • 3
  • 31
  • 40
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.

Community
  • 1
  • 1
Gordon
  • 312,688
  • 75
  • 539
  • 559
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
  • 2
    While 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
  • @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
    Hint: Typecasting is not necessary. – aProgger Sep 06 '19 at 07:12
  • 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.

Community
  • 1
  • 1
Fidi
  • 5,754
  • 1
  • 18
  • 25
0

If you're working with timestamps

echo time()+60*60*24*365
Flask
  • 4,966
  • 1
  • 20
  • 39
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'));>