iconic Posted January 26, 2011 Share Posted January 26, 2011 This must be less complex than what it sounds like. I want to find out the users that have logged in my page in LESS THAN 48 hours in the first trimester of last year. And place them in another table. My MySql DB has a table with "user id" and "date" fields. I have sorted out users that have visited only once in that trimester, leaving only duplicates: with repeating "userid" but with different "date". I have spent days now trying to figure out how to use de date_diff function to solve this. My date format is d/m/y. Please help with code! Thank you. (excuse my english) Quote Link to comment https://forums.phpfreaks.com/topic/225780-users-who-re-visit-in-less-than-48-hours/ Share on other sites More sharing options...
codefossa Posted January 26, 2011 Share Posted January 26, 2011 Add a `visted` column and update their time on each refresh by adding it to the template to update their row. Then just grab the SQL table WHERE `visited` > $time when $time = time() - (48 * 60 * 60); Quote Link to comment https://forums.phpfreaks.com/topic/225780-users-who-re-visit-in-less-than-48-hours/#findComment-1165630 Share on other sites More sharing options...
Pikachu2000 Posted January 26, 2011 Share Posted January 26, 2011 Or even better, use the native MySQL time manipulation functions. SELECT `record` FROM `table` WHERE `datetime_field` > ( DATE_SUB(NOW(), INTERVAL 48 HOURS) ) Quote Link to comment https://forums.phpfreaks.com/topic/225780-users-who-re-visit-in-less-than-48-hours/#findComment-1165639 Share on other sites More sharing options...
iconic Posted January 26, 2011 Author Share Posted January 26, 2011 Pikachu2000: Your solution is very helpful if MySqls allow_invalid_dates function would work. Remember my format is dd/mm/yy. It converted my dates to 0000-00-00. Unless there is a function I am unaware of. i believe this option is discarded. Kira: I´m burning my neurons using your solution here, and I think it will work. I am sure as a beginner in PHP I can figure it out. Thanks for the help! I´ll post updates on my progress. Quote Link to comment https://forums.phpfreaks.com/topic/225780-users-who-re-visit-in-less-than-48-hours/#findComment-1165667 Share on other sites More sharing options...
Pikachu2000 Posted January 26, 2011 Share Posted January 26, 2011 I didn't notice the format, but why not convert the dates to a valid format and store them in the proper field type? Quote Link to comment https://forums.phpfreaks.com/topic/225780-users-who-re-visit-in-less-than-48-hours/#findComment-1165671 Share on other sites More sharing options...
iconic Posted January 27, 2011 Author Share Posted January 27, 2011 I didn't notice the format, but why not convert the dates to a valid format and store them in the proper field type? Ha! Because I have no idea how to. I am looking it up right now, to see how! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/225780-users-who-re-visit-in-less-than-48-hours/#findComment-1165885 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.