Forum Moderators: open

Message Too Old, No Replies

MySQL, age of record

         

bysonary

12:49 pm on Jun 18, 2007 (gmt 0)

10+ Year Member



hello

I was hoping that someone here could help

I am a newbie to databases, been working with them for a little over 6 months and was hoping if someone could tell me if it possible to keep the age of a certain record in a field for that record.

My original plan was to use php to increment the age whenever the script was run, the only problem with that is, if the script wasnt run everyday then the age wouldnt be incremented by one everyday and i want it to be incremented by one every day.

So say a record is a year old, the value of the field for that record would be 365

I have heard of cron and thought about running this php script as a cron job but have since found out that my shared host doesn't let users run scripts as cron jobs, which i suppose is understandable.

So i was thinking if mysql has a mechanism in it that would automatically increment the field by 1 every 24 hours it would be sweet, my plan is to check if the field is greater than a certain amount and after so long have it automatically be deleted. Again the only way i can think of doing this is with php, perhaps there isnt a way in doing it without php and cron but worth a try, if anyone can help please do.

Thanks

ChrisW

PS: if the field can be incremented without php it be nice, thats all im really looking for to be honest, i can run the script to check the value of the field sporadically whenever i log into my system, as long as the field can be incremented automatically by one every 24 hours.

SuzyUK

1:24 pm on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not too sure on the how,
but wouldn't a "date created" field, created when the record is input, as UNIX timestamp do

that way you could always subtract it from today's timestamp to find the age/get the value regardless of when script is run

phranque

10:20 pm on Jun 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can easily calculate the age using time functions on the select if you maintain a "date created" field in the record.