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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.