squiblo Posted September 15, 2009 Share Posted September 15, 2009 hi, i have a date store in my database like "Y-m-d" (2009-10-16) and i have selected this from the database and stored it in a variable called $startdate ($startdate = $row['registered')... how can i add 1 year onto this date and store the new date in a variable called $enddate? <?php mysql_connect("localhost","","") or die ("Couldn't connect"); mysql_select_db("") or die ("Couldn't find db"); $query = mysql_query("SELECT * FROM members where username='$username'"); $row = mysql_fetch_assoc($query); $startdate = $row['registered']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/174382-solved-changing-dates-in-a-variable/ Share on other sites More sharing options...
MadTechie Posted September 15, 2009 Share Posted September 15, 2009 If you want to do it via the SQl you could do this $query = mysql_query("SELECT DATE_ADD(registered, INTERVAL 1 YEAR) as enddate FROM members where username='$username'"); $startdate = $row['registered'); $enddate= $row['enddate'); or via PHP $enddate= date( "Y-m-d", strtotime( "$startdate +1 year" ) ); Quote Link to comment https://forums.phpfreaks.com/topic/174382-solved-changing-dates-in-a-variable/#findComment-919206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.