Select data based on timestamp and interval from mysql
In joomla, it has jos_session table in which time is stored as unixtimestamp in 'time' column. I want to select the records which are older then a week or two days, basically any interval.
Not much hands on DB, but i did tried with date_sub, but it seems taking date as an argument. So I开发者_如何学JAVA also tried using FROM_UNIXTIME to convert, but nothing seems to be working.
The last query I tried was
SELECT username FROM jos_session WHERE DATE_SUB(FROM_UNIXTIME(time,'Y-m-d'), INTERVAL 2 DAY );
But it seems to giving empty set and many warnings!
Can anyone please help!
Thanks in advance, Tanmay
Try this. It should work:
SELECT
username
FROM
jos_session
WHERE
TO_DAYS(FROM_UNIXTIME(CAST(
timeAS UNSIGNED))) < TO_DAYS(FROM_UNIXTIME(UNIX_TIMESTAMP()))-2
精彩评论