Reputation: 9111
Im selecting the following time from MySQL from a row:
2013-02-05 11:05:20
I want to see if 30 minutes have passed..
This is what I've tried so far, but cant seem to get it to work:
if(strtotime($row['last_visit']) > strtotime("-30 minutes")) {
$database->query("UPDATE `visit_count` SET visitCount = visitCount + 1, cookieId = '$sid', last_visit='$idag' WHERE cookieId = '$sid' AND ipaddress = '$ip'");
}
last_visit = 2013-02-05 11:05:20 in the database
Upvotes: 1
Views: 887
Reputation: 2540
$database->query("UPDATE `visit_count` SET visitCount = visitCount + 1, cookieId = '$sid', last_visit='$idag' WHERE cookieId = '$sid' AND ipaddress = '$ip'" and MINUTES(last_visit)=MINUTES(TIMESTAMP())-30);
It may help you.there may be some syntax error. Internet is creating problem here. optimise syntax error from http://dev.mysql.com/doc/refman/5.1/en/datetime.html
Upvotes: 1
Reputation: 3904
Try this:
if((time()-1800) > strtotime($row['last_visit']) { // 3600 is one hour, so 1800 is 30 minutes
Upvotes: 0
Reputation: 1469
You have to compare with cuurrent time
if(strtotime($row['last_visit']) < (time() -(30*60)) {
$database->query("UPDATE `visit_count` SET visitCount = visitCount + 1, cookieId = '$sid', last_visit='$idag' WHERE cookieId = '$sid' AND ipaddress = '$ip'");
}
Upvotes: 1