Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$date + 1 year?

Tags:

php

strtotime

I'm trying to get a date that is one year from the date I specify.

My code looks like this:

$futureDate=date('Y-m-d', strtotime('+one year', $startDate)); 

It's returning the wrong date. Any ideas why?

like image 449
Matt Avatar asked Dec 15 '09 03:12

Matt


People also ask

How to add 1 year in php date?

$futureDate=date('Y-m-d', strtotime('+one year', $startDate));

How can I get plus date in PHP?

The date_add() function adds some days, months, years, hours, minutes, and seconds to a date.

What is Strtotime PHP?

The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.


1 Answers

$futureDate=date('Y-m-d', strtotime('+1 year')); 

$futureDate is one year from now!

$futureDate=date('Y-m-d', strtotime('+1 year', strtotime($startDate)) ); 

$futureDate is one year from $startDate!

like image 94
Misho Avatar answered Sep 21 '22 18:09

Misho