This question already has an answer here:
I try to get the relative date and time from the MySQL NOW()
function, (like 2 seconds ago, 3 days ago, on the 31st of december...) but I have no idea how! Any ideas? Thank you so much!
This question already has an answer here:
I try to get the relative date and time from the MySQL NOW()
function, (like 2 seconds ago, 3 days ago, on the 31st of december...) but I have no idea how! Any ideas? Thank you so much!
Use
TIMESTAMPDIFF()
function. See example:Or use this stored function:
For query:
Shows:
You must specify the time, or in your case the seconds, beforehand.
Let me illustrate what I mean, with simple example, based on a PDO-Mysql query
In the above example, if you use the query, you will actually be searching for a user whose login time, is less than
$time
or01:00:00