poe Posted March 9, 2007 Share Posted March 9, 2007 my table has: id | user | month | year 1 | chris | 6 | 2006 2 | chris | 12 | 2006 3 | chris | 1 | 2007 4 | mary | 6 | 2007 5 | mary | 11 | 2007 6 | chris | 8 | 2007 7 | chris | 9 | 2007 8 | chris | 1 | 2008 9 | chris | 4 | 2008 how do i select just the records that belong to a certain user 'chris' that are months in the future so since 2006 has passed, id 1, id 2 will be skipped, id3 will also skip Link to comment https://forums.phpfreaks.com/topic/41914-future-dates/ Share on other sites More sharing options...
btherl Posted March 9, 2007 Share Posted March 9, 2007 It would be easier if you used a date data type instead.. but since you've got integers (are they integers? or varchars?), you can do $cur_month = date('m'); $cur_year = date('Y'); $sql = "SELECT * FROM table WHERE user = 'chris' AND (year > $cur_year OR (month > $cur_month AND year = $cur_year))"; You can also fetch the date from within mysql, but I'm not familiar with how to do that. Edit: Oops.. fixed silly mistake Link to comment https://forums.phpfreaks.com/topic/41914-future-dates/#findComment-203239 Share on other sites More sharing options...
fenway Posted March 9, 2007 Share Posted March 9, 2007 Yeah, much easier with dates... and mysql will even let you store incomplete ones, like 2006-01-00. Link to comment https://forums.phpfreaks.com/topic/41914-future-dates/#findComment-203541 Share on other sites More sharing options...
poe Posted March 21, 2007 Author Share Posted March 21, 2007 ok thanks, i will have to try that Link to comment https://forums.phpfreaks.com/topic/41914-future-dates/#findComment-211811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.