brett24 Posted January 27, 2007 Share Posted January 27, 2007 I've been on a seemingly simple task for two days now. I'm hoping someone here can give me a hand. I'm trying to write code to do the following. (I've always had a bit of a mental block on the date and time functions with php.)Insert into a mysql table today's date //this I'm thinking I can do by setting $var=now() Also insert today's date plus one year (to show the end date of the annual membership period).//pulling my hair on how to add a yearAlso, if the member renews the membership I need to be able to add another year to membership period (without losing the time left on the current annual period - so if they have a month left, the new end date would be 13 months into the future after adding another year).Thanks for any help.-Brett Quote Link to comment https://forums.phpfreaks.com/topic/36001-solved-phpmysql-date-manipulation-for-annual-membership-periods/ Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 today:$sql = "INSERT INTO table(field) VALUES(now())"; Don't use a variable, just do now()plus a year$year = time()+(60*60*24*365); Quote Link to comment https://forums.phpfreaks.com/topic/36001-solved-phpmysql-date-manipulation-for-annual-membership-periods/#findComment-170780 Share on other sites More sharing options...
brett24 Posted January 27, 2007 Author Share Posted January 27, 2007 [quote author=jesirose link=topic=124348.msg515033#msg515033 date=1169941078]today:$sql = "INSERT INTO table(field) VALUES(now())"; Don't use a variable, just do now()plus a year$year = time()+(60*60*24*365);[/quote]Thanks. I'll do the first part. For the second part I was hoping to find a '+1 year' sort of solution that takes care of leap years too. I then need to be able to call the value from mysql (the end date of the membership) and add a year at any time. Any thoughts on that?-Brett Quote Link to comment https://forums.phpfreaks.com/topic/36001-solved-phpmysql-date-manipulation-for-annual-membership-periods/#findComment-170786 Share on other sites More sharing options...
bibby Posted January 28, 2007 Share Posted January 28, 2007 time() is an ok solution if you are always going a year from now, but memberships are most often renewed before they expire.So if my expiration date is 2007-06-01 (date format, not unix time), and I wanted a add a year from THEN, try[code]update members set expDate =concat( date_format(expDate,'%Y')+1 ,date_format(expDate,'-%m-%d') )where mbrID=1;[/code]That gets you year beyond what I'm already due.Be careful that if the membership is expired already not to shirtchange them, (use now)[code]concat( date_format(now(),'%Y')+1 ,date_format(now(),'-%m-%d'))#year from now without php[/code]How you handle leap years is up to you. What you consider correct is correct.This method grants the occasional 366 day-year. Quote Link to comment https://forums.phpfreaks.com/topic/36001-solved-phpmysql-date-manipulation-for-annual-membership-periods/#findComment-170845 Share on other sites More sharing options...
brett24 Posted January 28, 2007 Author Share Posted January 28, 2007 Terrific.Thank you.I'll give that a try tonight.-Brett Quote Link to comment https://forums.phpfreaks.com/topic/36001-solved-phpmysql-date-manipulation-for-annual-membership-periods/#findComment-170885 Share on other sites More sharing options...
brett24 Posted January 29, 2007 Author Share Posted January 29, 2007 Hey Bibby.That elegant little bit of code worked great.Thanks.-Brett Quote Link to comment https://forums.phpfreaks.com/topic/36001-solved-phpmysql-date-manipulation-for-annual-membership-periods/#findComment-171615 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.