"Resetting" Dates based on seconds
Posted: Wed Dec 08, 2010 3:18 pm
Hey Guys,
I'm working on an auction site that uses datetime fields in MySQL to determine the time left in an auction. Time is added to the auction however, each time a bid is placed.
The rules are every bid adds 1 second to the timer. If the timer is under 15 seconds, a bid resets the timer to 15 seconds.
The problem we're facing is that often the timer will go past 15 seconds if heavy bids are being placed, instead of "resetting" to 15 seconds. Here's what we currently have:
Any help would be really appreciated!
I'm working on an auction site that uses datetime fields in MySQL to determine the time left in an auction. Time is added to the auction however, each time a bid is placed.
The rules are every bid adds 1 second to the timer. If the timer is under 15 seconds, a bid resets the timer to 15 seconds.
The problem we're facing is that often the timer will go past 15 seconds if heavy bids are being placed, instead of "resetting" to 15 seconds. Here's what we currently have:
The end_dt is the date we use to determine the time left in an auction (or seconds left). The now() is a function that simply supplies a mysql datetime based off a specified time zone - so it's an equivalent to mysql's now(), just set for specific local.UPDATE `auctions` SET end_dt =
IF(TIME_TO_SEC(TIMEDIFF(end_dt,'".now()."')) <= 15,
DATE_ADD(STR_TO_DATE(end_dt,'%Y-%m-%d %H:%i:%s'),
INTERVAL (15 - TIME_TO_SEC(TIMEDIFF(end_dt,'".now()."'))) SECOND),
DATE_ADD(STR_TO_DATE(end_dt,'%Y-%m-%d %H:%i:%s'), INTERVAL 1 SECOND))
WHERE id = '".$id."'
Any help would be really appreciated!