I keep a record of logins in a table. I have columns for id, ip, date and time. From that record of logins I wanna fetch logins made only in the last hour.
I'm sweeping through the MySQL docs on time and date functions, but I just can't seem to combine them correctly.
Can somebody help me?
it can be done easily using
If you want to implement this into a cronjob, you need to specify the start and end.
For example, at 2pm, if you want to get the data for the past hour from 13:00:00 until 13:59:59, here's how to do it:
without the specifics, I think Date_Add() would work.. by adding to your where clause an add of NOW negative hours
(or Date_Sub() )
Make use of the DATE_SUB() and Now() functions:
Hope it helps you : )
I recommend have one datetime column instead of date and time columns.
Suppose you have a datetime column called last_login:
You can also use CURDATE()function