Is there a way to compare a datetime field in mySQL with the current date and return the time difference? I don't really know where to start so if anyone has an idea, please point me to the right direction.
Here's what I already tried.
SELECT *
FROM `order`
WHERE `dateTimeAdded` - NOW( ) <1;
basically what I am trying to achieve is to get the orders which is saved for more than 8 hours in the database. Thanks!
If you want your query to have a chance of using an index on the datetime column, you should not do manipulation (functions) on the column but only on the other side:
SELECT *
FROM `order`
WHERE dateTimeAdded < NOW( ) - INTERVAL 8 HOUR ;
If u just need the diff of dates use DATEDIFF(now(), column)
and if you need the time difference use TIMEDIFF(now(),column)
DATEDIFF(date1,date2);
Taken FROM