PDA

View Full Version : timestamp math


jbroder
02-19-2000, 09:09 PM
I am working on a voting system with php and mysql.
It tracks votes on a variety of topics.
I have it set up to log the REMOTE_ADDR of each voter so that no one can vote over and over again.

I don't need to keep the IPs and votes indefinitely. I just want to prevent one IP from voting twice in the same day or hour or something. So I want to delete old IPs when new votes are logged.

I put in a TIMESTAMP(14) called moddate. I want to use that for the query that deletes old vote logs. Something like
DELETE FROM table where (moddate < yesterday)

The trouble is, I can't figure out how to tell the database &quot;yesterday&quot;.

My php time() format is different from the TIMESTAMP format.
(moddate < timestamp -3600) doesn't work

and I don't understand the mysql manual, which seemed to suggest
(moddate < CURRENT_TIME - 3600) doesn't work

Can anybody help?

Thanks,
Jon

Justin
02-19-2000, 09:32 PM
CURRENT_TIME returns a MySQL time stamp, and you would not be able to (easily) subtract from that. Try this:
</font><font face="Courier" size="3">
$yesterday = date (&quot;Y-m-d H:i:s&quot;, time() - 3600);
delete from table where moddate < '$yesterday';
</font><font face="Verdana, Arial" size="2">
Hope this helps.

------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support