9three Posted September 13, 2009 Share Posted September 13, 2009 Hey, I'm using the date function in MySQL CURDATE to store the date of a post. What I'm trying to do is show posts that are from today's date and 7 days ago. So what Im trying to do is something like this: SELECT fname, lname, date, time FROM posts BETWEEN CURDATE() AND ??? I'm trying to figure out how to do CURDATE minus 7 (1 week ago) Anyone know how to accomplish this? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/174051-solved-retrieving-1-weeks-worth-information/ Share on other sites More sharing options...
fenway Posted September 13, 2009 Share Posted September 13, 2009 BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/174051-solved-retrieving-1-weeks-worth-information/#findComment-917516 Share on other sites More sharing options...
9three Posted September 13, 2009 Author Share Posted September 13, 2009 oh thanks mate. Quote Link to comment https://forums.phpfreaks.com/topic/174051-solved-retrieving-1-weeks-worth-information/#findComment-917654 Share on other sites More sharing options...
fenway Posted September 13, 2009 Share Posted September 13, 2009 I should probably add that WHERE `date` > CURDATE() - INTERVAL 7 DAY would likely have better index utilization. BTW, why are you storing time separately? Quote Link to comment https://forums.phpfreaks.com/topic/174051-solved-retrieving-1-weeks-worth-information/#findComment-917807 Share on other sites More sharing options...
9three Posted September 13, 2009 Author Share Posted September 13, 2009 Is it possible to retrieve only part what I need from each column? For example If I store the date and time in the same column would I be able to pull only the time if necessary? Or the date alone? Quote Link to comment https://forums.phpfreaks.com/topic/174051-solved-retrieving-1-weeks-worth-information/#findComment-917877 Share on other sites More sharing options...
fenway Posted September 14, 2009 Share Posted September 14, 2009 Absolutely... use DATE() or TIME(), or their respective format functions. Quote Link to comment https://forums.phpfreaks.com/topic/174051-solved-retrieving-1-weeks-worth-information/#findComment-918171 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.