markvaughn2006 Posted September 20, 2009 Share Posted September 20, 2009 I know this should be pretty simple...can't figure it out though. I have a field that tells how long a person has been a member, when they sign up it fills in the date that they joined, is there a way to add 1 to a days_old field each new day?? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/174850-solved-add-1-to-a-field-every-day/ Share on other sites More sharing options...
MadTechie Posted September 20, 2009 Share Posted September 20, 2009 UPDATE table SET days_old=days_old+1 however, you could do it during the select and not use a field SELECT *, DATEDIFF(NOW(),joindate)+1 as days_old FROM table EDIT: the +1 would mean from the second they start its 1 day old, so you may want to remove it Quote Link to comment https://forums.phpfreaks.com/topic/174850-solved-add-1-to-a-field-every-day/#findComment-921460 Share on other sites More sharing options...
markvaughn2006 Posted September 20, 2009 Author Share Posted September 20, 2009 Thanks for the quick reply I would have to manually run this code every day though wouldn't I? UPDATE table SET days_old=days_old+1 The second one is a little over my head... Quote Link to comment https://forums.phpfreaks.com/topic/174850-solved-add-1-to-a-field-every-day/#findComment-921464 Share on other sites More sharing options...
MadTechie Posted September 20, 2009 Share Posted September 20, 2009 Yes your need to run it everyday.. or you could do this and it will update to the correct date even if you skipped a day.. UPDATE table SET days_old=DATEDIFF(NOW(),joindate)+1 However the real question is why do you wish to update the field ? I assume you are pulling data from a database and you need to know how may days the account has been active. right ? question #2 field you have that stores the date they joined.. what type is that and what's its name? Quote Link to comment https://forums.phpfreaks.com/topic/174850-solved-add-1-to-a-field-every-day/#findComment-921467 Share on other sites More sharing options...
markvaughn2006 Posted September 20, 2009 Author Share Posted September 20, 2009 yep I'm wanting to know how many days the account has been active, the field name is date_first and the format of it is 16-09-2009. The field that will actually say how many days account has been active is called days_old. I did some research on DATEDIFF and thats exactly what I need, thanks for all your help!! -solved- Quote Link to comment https://forums.phpfreaks.com/topic/174850-solved-add-1-to-a-field-every-day/#findComment-921499 Share on other sites More sharing options...
MadTechie Posted September 20, 2009 Share Posted September 20, 2009 Your welcome You know.. if you removed the days_old and in your select statement changed the * to *, DATEDIFF(NOW(),joindate)+1 as days_old ie change SELECT * FROM table to SELECT *, DATEDIFF(NOW(),joindate)+1 as days_old FROM table you would still get the days_old field without needed to update it everyday Quote Link to comment https://forums.phpfreaks.com/topic/174850-solved-add-1-to-a-field-every-day/#findComment-921503 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.