t_machine Posted June 2, 2009 Share Posted June 2, 2009 Hi, I have a table in mysql database that stores download_file, download_date(DATETIME), user_id How can i get the files downloaded in the last 7 days? I am using the following but does not seem to work. $sql = 'SELECT download_file FROM {my_table} WHERE DATE_FORMAT(download_date, "%d%m%y") >= DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 7 DAY), "%d%m%y")'; Quote Link to comment https://forums.phpfreaks.com/topic/160709-solved-how-to-get-db-results-for-the-last-7-days/ Share on other sites More sharing options...
ldougherty Posted June 2, 2009 Share Posted June 2, 2009 Can you show us an example of an entry in the database? Quote Link to comment https://forums.phpfreaks.com/topic/160709-solved-how-to-get-db-results-for-the-last-7-days/#findComment-848145 Share on other sites More sharing options...
Maq Posted June 2, 2009 Share Posted June 2, 2009 This should work: $sql = "SELECT download_file FROM my_table WHERE download_date > DATE_SUB(NOW(), INTERVAL 7 DAY)"; Quote Link to comment https://forums.phpfreaks.com/topic/160709-solved-how-to-get-db-results-for-the-last-7-days/#findComment-848146 Share on other sites More sharing options...
t_machine Posted June 3, 2009 Author Share Posted June 3, 2009 Thank you, it does work. Seems there was also another issue that was in part causing the original codes to not work. Quote Link to comment https://forums.phpfreaks.com/topic/160709-solved-how-to-get-db-results-for-the-last-7-days/#findComment-848270 Share on other sites More sharing options...
Maq Posted June 3, 2009 Share Posted June 3, 2009 Thank you, it does work. Seems there was also another issue that was in part causing the original codes to not work. Does everything work now? Quote Link to comment https://forums.phpfreaks.com/topic/160709-solved-how-to-get-db-results-for-the-last-7-days/#findComment-848531 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.