Reputation: 6629
I would like to select all trucks wityh a certain status and where created_at is past 24 hours
This is what i have tried
SELECT * FROM tbl_trucks WHERE `truck_status` != 11
Now am stuck on how to add the extra where statement such that i get only the trucks that are past 24 hours from current time. In literal terms this would be
SELECT * FROM tbl_trucks WHERE `truck_status` != 11
ANDWHERE ('created_at'-NOW() <0 ) //created_at passes 24 hours
In usual php this would translate to
$created_at= 1500373706; // created_At value in mysql db
if ((time() - $created_at) > 86400) { //past 24 hours mark
//past 24 hours i need these
} else {
//not past 24 hours i dont need them
}
Upvotes: 0
Views: 52
Reputation: 521053
You can try using the following query to find all records whose status is not 11
and which were created in the last day:
SELECT t.*
FROM tbl_trucks t
WHERE t.truck_status <> 11 AND
t.created_at < NOW() - INTERVAL 1 DAY
Upvotes: 1
Reputation: 1269623
It is something like:
SELECT t.*
FROM tbl_trucks t
WHERE t.truck_status <> 11 AND
t.created_at < DATE_SUB(NOW(), INTERVAL 24 HOUR);
Upvotes: 1