Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP 1

Status
Not open for further replies.

thewhistler1

Technical User
Jan 20, 2008
35
US
Does anyone know how to use strtotime to give me a variable date + 1 year?
I know how to do it using todays date like this:

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

but I want to use a date that was entered in a form instead of todays date. I tried the following but it did not work.

$date = "2008-06-16";
$newdate = $date("Y-m-d",strtotime('+1 year'));
echo $newdate ;

Any ideas? Thanks in advance.
 
bit counter intuitive...
Code:
$date = "2008-06-16";
$newdate = $date("Y-m-d",strtotime('+1 year', strtotime($date)));
echo $newdate ;
 
Thanks jpadie,

I had to alter it to the following to get it to work but now it is working.

$date = "2008-06-16";
$newdate = date("Y-m-d",strtotime('+1 year', strtotime($date)));
echo $newdate ;

Excellent!!
 
ah yes. i just copied and pasted your code above and fixed the right hand side without checking the left. function names cannot begin with a $ unless you are referencing a variable function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top