JSHINER Posted March 21, 2007 Share Posted March 21, 2007 Trying to figure out how to show records that are current day & beyond - no past. I don't want them to delete from the database, I just want the page to display records that are either current date or future. Any help would be much appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/ Share on other sites More sharing options...
Orio Posted March 21, 2007 Share Posted March 21, 2007 Do you have some sort of column that holds a date or a timestamp? In what format? Orio. Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212246 Share on other sites More sharing options...
majocmatt Posted March 21, 2007 Share Posted March 21, 2007 I'll assume your just using YYYY-MM-DD, the DATE format in a database. If not, you can adapt your timestamp to the following: Create a variable for $now where $now = date("Y-m-d"); And query the database SELECT * FROM myTable WHERE date >= $now Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212250 Share on other sites More sharing options...
JSHINER Posted March 21, 2007 Author Share Posted March 21, 2007 Sorry - should have included that: I have a field "date" and the date is entered by the user in the 00/00/2007 format. I need a page that will display results that are either the current date, or future dates. Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212254 Share on other sites More sharing options...
grimmier Posted March 21, 2007 Share Posted March 21, 2007 $sql='SELECT * FROM `db_name` WHERE `date_field` >= "low_range" ORDER BY `date_field` DESC'; try something like that, filling in the db_name, date_field, and low_range with your variables. Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212267 Share on other sites More sharing options...
grimmier Posted March 21, 2007 Share Posted March 21, 2007 Sorry - should have included that: I have a field "date" and the date is entered by the user in the 00/00/2007 format. I need a page that will display results that are either the current date, or future dates. is the date stored as in DATE format in the DB or as a VARCHAR? Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212268 Share on other sites More sharing options...
JSHINER Posted March 21, 2007 Author Share Posted March 21, 2007 It can be stored as either - I haven't created it yet. So low range - how can I have that be the current date? Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212272 Share on other sites More sharing options...
grimmier Posted March 21, 2007 Share Posted March 21, 2007 It can be stored as either - I haven't created it yet. So low range - how can I have that be the current date? $low_range = date("Y-m-d"); //will set the low range to the current date, formatted in yyyy-mm-dd format (which is standard for mysql db's anyway) You can still allow the users who do the inputting to enter their dates in mm-dd-yy format if you want, and reformat it before inserting it, into the DB, thats the method i use personally. $low_range = date("Y-m-d"); $sql='SELECT * FROM `db_name` WHERE `date_field` >= "'.$low_range.'" ORDER BY `date_field` DESC'; Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212279 Share on other sites More sharing options...
JSHINER Posted March 21, 2007 Author Share Posted March 21, 2007 How would I re-format before inserting ? Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212293 Share on other sites More sharing options...
grimmier Posted March 21, 2007 Share Posted March 21, 2007 http://www.phpfreaks.com/forums/index.php/topic,127739.15.html thats the thread i started when i was wondering the same thing. the solution is twards the end. Link to comment https://forums.phpfreaks.com/topic/43720-display-by-date/#findComment-212355 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.