tags:

views:

24

answers:

1

Hi,

In a mysql table for a date column(login_time), i need to get the logins for

last 30 days, last 60 days.

Is there any way to do that?

Thanks.

+3  A: 

this will give you the rows from the table where login_time is within the last 60 days:

SELECT * FROM table WHERE login_time >= SUBDATE(CURDATE(),INTERVAL 60 DAY)

similarly with 30 days.

Piskvor
Note the addDate (3x`D`) and 60 `DAY` (not "dayS")
Piskvor
Thanks, will it give me login_time of last 30 days logged in users?
Sharpeye
Not good as query optimizer cannot used index by login_time and need arithmetic for every record. Better to apply adddate to curdate()
@burnall: Good point, edited.
Piskvor