Jump to content


Photo

date calculations


  • Please log in to reply
4 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 11 September 2006 - 03:27 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 11 September 2006 - 03:42 PM

Please.... for our own sanity... if you're going to ramble for that long, break it up with a few presses of the "Enter" key from time to time.  No one wants to read a giant hunk of text like that.

Info: PHP Manual


#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 11 September 2006 - 03:46 PM

Got half away through that before I started to get a headache. I'll come back and read the other half after I recover. Hopefully then I will be able to offer some advice.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 September 2006 - 04:05 PM

I always record the date like 09-11-06


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!!!!
Legend has it that reading the manual never killed anyone.
My site

#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 11 September 2006 - 05:36 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users