Jump to content

[SOLVED] Add 1 to a field every day


markvaughn2006

Recommended Posts

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

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?

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-

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

Archived

This topic is now archived and is closed to further replies.

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