Jump to content

[SOLVED] changing dates in a variable


squiblo

Recommended Posts

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'];
?>

Link to comment
https://forums.phpfreaks.com/topic/174382-solved-changing-dates-in-a-variable/
Share on other sites

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" ) );

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.