开发者

Select data based on timestamp and interval from mysql

开发者 https://www.devze.com 2023-01-27 06:35 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消