geroid Posted October 3, 2009 Share Posted October 3, 2009 Hi I have records in a table that I want to select by their date. I only want records to be extracted that are equal to or greater than todays date. I have the following statement but it's not working. The variable $todaydate literally holds todays date. So I'm comparing the event_date with the variable. Is this how I should do it? At the moment, all the records are being extracted. Can you help? $query = "select event_num, event_name, venue_name, streetaddress1, town, county, event_description_ire, event_description_eng, event_date, event_time from $table where event_date >= $todaydate order by event_num desc"; Quote Link to comment https://forums.phpfreaks.com/topic/176407-solved-help-with-selecting-record-by-date/ Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Yes, that basically looks right, is the format of the column DATETIME? What format is $todaydate in? Quote Link to comment https://forums.phpfreaks.com/topic/176407-solved-help-with-selecting-record-by-date/#findComment-929789 Share on other sites More sharing options...
geroid Posted October 3, 2009 Author Share Posted October 3, 2009 Hi again cags The column is date not datetime and I get the variable content with the following: $todaydate = date("Y-m-d"); but it's not working Quote Link to comment https://forums.phpfreaks.com/topic/176407-solved-help-with-selecting-record-by-date/#findComment-929795 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Ahh, just realised, your not enclosing it in single quotes, put '$todaydate' in the query rather than just $todaydate Quote Link to comment https://forums.phpfreaks.com/topic/176407-solved-help-with-selecting-record-by-date/#findComment-929799 Share on other sites More sharing options...
geroid Posted October 3, 2009 Author Share Posted October 3, 2009 That did the trick again. Thanks cags. I hate to be so forgetful. I should have known that by now. Quote Link to comment https://forums.phpfreaks.com/topic/176407-solved-help-with-selecting-record-by-date/#findComment-929803 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.