Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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