[RESOLVED] MySQL's datetime - Hours passed?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

[RESOLVED] MySQL's datetime - Hours passed?

Post by [UW] Jake »

I wanted to make it so it would check if it's been an hour since any database entries with their IP. If not, don't let them post!

I figured it out using strtotime.

Code: Select all

$query  = "SELECT date, ip FROM A_Database_Name";
$result = mysql_query($query);
 
while(list($date, $postedIP) = mysql_fetch_array($result))
{
    //If the IP addresses match
    if($postedIP == $ip)
    {
        $posted = strtotime($date);
        $now = strtotime(date("Y-m-d H:i:s"));
        $seconds = $now - $posted;
        $hours = $seconds / 3600;
 
        if($hours < 1)
        {
                $error .= "You must wait 1 hour before re posting.";
                $continue = false;
                break;
        }
    }
}
Jake
Post Reply