denno020 Posted January 6, 2011 Share Posted January 6, 2011 This should be a lot more easier than I'm finding it... at least I would have thought so. What I'm trying to do is get all results from a database where the date set is before the current date (right now). I tried by setting a variable $dateNow using date("Y-m-d"), but that didn't seem to work.. How do I put a WHERE clause saying that the date field in a row has to be before the current date? Thanks Denno Quote Link to comment https://forums.phpfreaks.com/topic/223553-getting-table-rows-before-the-current-date/ Share on other sites More sharing options...
Adam Posted January 6, 2011 Share Posted January 6, 2011 What data type are you using for the date column? You shouldn't need to use PHP to generate the date, MySQL has a built-in function called curdate() which will do that for you.. select * from table_name where date_column < curdate() Quote Link to comment https://forums.phpfreaks.com/topic/223553-getting-table-rows-before-the-current-date/#findComment-1155609 Share on other sites More sharing options...
denno020 Posted January 6, 2011 Author Share Posted January 6, 2011 I've set the field type as just date. If I print out the date it will print like YYYY-MM-DD.. I've give your suggestion a go and report back . Thanks Denno Quote Link to comment https://forums.phpfreaks.com/topic/223553-getting-table-rows-before-the-current-date/#findComment-1155667 Share on other sites More sharing options...
denno020 Posted January 6, 2011 Author Share Posted January 6, 2011 From the looks of it, this worked perfectly. Thanks for the help mate Denno Quote Link to comment https://forums.phpfreaks.com/topic/223553-getting-table-rows-before-the-current-date/#findComment-1155682 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.