Jump to content

adding an expiration date


lauralee

Recommended Posts

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

what do you mean by adddate function? are you using timestamp to store register time?

Link to comment
Share on other sites

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 by thescientist
Link to comment
Share on other sites

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 by astralaaron
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...