In PHP i am using the following to see if 30 minutes have passed:
if(strtotime($rowFromMysql['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' AND user_id = '$ssid'");
}
How would i do the same check in Nodejs?
I am selecting the same data from MySQL but in nodejs instead of PHP but have no idea how to see if 30 minutes have passed.
Any ideas?
You could do something similar to your code using Date objects:
var lastVisit = new Date(getLastVisit());
var thirtyMinutes = 30 * 60000; // 60000 being the number of milliseconds in a minute
var now = new Date();
var thirtyMinutesAgo = new Date(now - thirtyMinutes);
if (lastVisit < thirtyMinutesAgo) {
updateVisitCount();
}
getLastVisit() should query your database and return your last visit date either as a: