jakeoh Posted January 4, 2008 Share Posted January 4, 2008 Hi, I want to have mySQL return users that went to my site in the last 7 days. When a user logs in or uses the website, the 'timestamp' column in the database is updated with the current timestamp. The MySQL query I have so far to get the list of active users in the past 7 days is as follows: $q = "SELECT username, first_name, last_name FROM ".TBL_USERS." WHERE timestamp > (UNIX_TIMESTAMP() - '604800000') ORDER BY timestamp DESC,username"; This query however get the users that were active more than 7 days ago. What is wrong with it? How would you build your query? Quote Link to comment https://forums.phpfreaks.com/topic/84555-solved-timestamp-date-and-calculations/ Share on other sites More sharing options...
jakeoh Posted January 4, 2008 Author Share Posted January 4, 2008 Sorry, I somehow thought timestamp was calculated in milliseconds. Using 604800 instead of 604800000 solved it. Quote Link to comment https://forums.phpfreaks.com/topic/84555-solved-timestamp-date-and-calculations/#findComment-430809 Share on other sites More sharing options...
fenway Posted January 5, 2008 Share Posted January 5, 2008 You really should be using INTERVAL 7 DAY for this. Quote Link to comment https://forums.phpfreaks.com/topic/84555-solved-timestamp-date-and-calculations/#findComment-430925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.