Jump to content

date calculations


Ninjakreborn

Recommended Posts

I have something that I find myself doing quite a bit, but I end up doing it the same way everytime.  I have a number, for instance 30.  I need it to go down daily, like if 3 days go by, I need it to be 27, and so forth until it hit's 0, then I can do something with it.  Like a timeperiod of how long something can be active.  The thing is I always record the date like 09-11-06 or something in the database, this is the date that the item, or whatever was entered into the database, then I have the current date.  I use something, like I decide when is the best imte, like right when they log in, or right when a specific page is open.  Then I check the date, turn it into a timestamp, record todays date, turn it into a timestamp, compare them, do some calculations, to make the date update, and that's it.  Then I go back, and above that, do a check for the 0 or less value, so it doesn't run unnecessary calculations, and instead either deletes the item, or moves it into another table for old items, or something, this would be whatever, a use with a timelimit on a paid account, or the lifetime of the post for a classified system.  does anyone know of a better way to do this, or a place I can put the information to run the script, somewhere that won't kill the server.  Because if I check all the entries in all the database, and update them all everytime someone logs in, or visits the site, then it might kill the server if a lot of people hit the site at once.  I don't really want that happened, and hoenstly, that many database calls at that many times, can calls db rewrites, and a lot of other things, and make the information in accurate. Or it could end up doing it 2-3 times before it updates the number, and make the number over-update. I am thinking of checking an individual users posts everything he/she logs into the site.  Then I also have the problem of people who create accounts, put some posts down then never come back to the site, they never get deleted.  Should I check each post individually.  Like if someone is browsing posts, go ahead and check then, or does anyone have another way of doing this, any advice, opinions are welcome, I have to do something to return a number of day's left, that's the whole point.
Link to comment
Share on other sites

[quote]I always record the date like 09-11-06[/quote]

Is that day month year, or month day year, or year month day, etc.  I bet you'll find doing anything with dates that it's simpler to use yyyy-mm-dd [the ISO standard date format] in your database. 

You can, of course, re-present dates drawn from the database in any format you want.

And Ober's right. Split it up into coherent thoughts in paragraphs. Make this stuff easier for us to read!!!!
Link to comment
Share on other sites

It's set up like month-date-year
I have it formatted in the databas,e I can save it however, if it's better then I will start saving it in that format.

The thing I was wondering was, is there another way to do calculations, or is there a good place to put the program to keep it from overloading the server, if a lot of people get it to do the same thing everytime.
Link to comment
Share on other sites

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.