lauralee Posted April 9, 2012 Share Posted April 9, 2012 I have a membership table that includes a field for the date that a membership was added. I want to be able to automatically sort the table by those memberships that have expired after one year from the date the membership was added. Below is the code that lists the members followed by the date of the membership. while ($row = @mysql_fetch_array($result)){ echo '<div class="memberdetails"><span class="second">' . $row['member_name'] . '</span> - ' . $row['membership_date'] . '<br />'; } I'm not sure how to use the ADDDATE function. Please give me a sample of code that would provide an expiration date that is one year after the membership_date. Link to comment Share on other sites More sharing options...
birbal Posted April 9, 2012 Share Posted April 9, 2012 what do you mean by adddate function? are you using timestamp to store register time? Link to comment Share on other sites More sharing options...
thescientist Posted April 10, 2012 Share Posted April 10, 2012 (edited) what would be more relevant to show us is how the membership date actually gets put into the database in the first place. Depending on the format you are saving it as (ideal would be a timestamp) it could be a simple case of addition, or just some work with the date function. and also as mentioned, what is this adddate function you speak of? Edited April 10, 2012 by thescientist Link to comment Share on other sites More sharing options...
astralaaron Posted April 10, 2012 Share Posted April 10, 2012 (edited) ADDDATE() is a mysql function: http://dev.mysql.com...unction_adddate similar to DATE_ADD() it will return the date with a certain amount of time added to it mysql> SELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY); -> '2008-02-02'mysql> SELECT ADDDATE('2008-01-02', INTERVAL 31 DAY); -> '2008-02-02' edit: so you could use that to determine if that row should expire or display Edited April 10, 2012 by astralaaron Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now