dbradbury Posted January 3, 2011 Share Posted January 3, 2011 i tried > and < but would work very well.. include("connect.php"); $getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id='17' ORDER BY post_subject ASC AND post_subject > $date"); just so you know.. that post subjects are dates formatted YYYY/MM/DD.. so they can be sorted. and i would like this code to select a the ones that are greater than or less than todays date.. can someone help me please? thanks Quote Link to comment Share on other sites More sharing options...
MMDE Posted January 3, 2011 Share Posted January 3, 2011 i tried > and < but would work very well.. include("connect.php"); $getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id='17' ORDER BY post_subject ASC AND post_subject > $date"); just so you know.. that post subjects are dates formatted YYYY/MM/DD.. so they can be sorted. and i would like this code to select a the ones that are greater than or less than todays date.. can someone help me please? thanks try this: include("connect.php"); $getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id=17 AND post_subject > '$date' ORDER BY post_subject ASC") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
dbradbury Posted January 3, 2011 Author Share Posted January 3, 2011 thanks for you help would i need to set $date to todays date? $date = date('Y/m/d') NOW(); or something? Quote Link to comment Share on other sites More sharing options...
gizmola Posted January 3, 2011 Share Posted January 3, 2011 I have written a couple of blog posts that cover mysql date and datetime types and calculations in detail. They might be helpful to you. http://www.gizmola.com/blog/archives/51-Exploring-Mysql-CURDATE-and-NOW.-The-same-but-different..html http://www.gizmola.com/blog/archives/99-Finding-Next-Monday-using-MySQL-Dates.html One other thing I can add is that you can use BETWEEN with mysql as an alternative to the > and Quote Link to comment Share on other sites More sharing options...
MMDE Posted January 3, 2011 Share Posted January 3, 2011 thanks for you help would i need to set $date to todays date? $date = date('Y/m/d') NOW(); or something? I would usually store dates in the format: date('Y-m-d') but then it doesn't store the time/clock... what you need and what your db is set till idk Quote Link to comment Share on other sites More sharing options...
dbradbury Posted January 3, 2011 Author Share Posted January 3, 2011 done i used CURDATE() so it was: $getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id=17 AND post_subject <= '$date' ORDER BY post_subject ASC"); Quote Link to comment Share on other sites More sharing options...
dbradbury Posted January 3, 2011 Author Share Posted January 3, 2011 done i used CURDATE() so it was: $getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id=17 AND post_subject <= '$date' ORDER BY post_subject ASC"); i meant $getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id=17 AND post_subject < CURDATE() ORDER BY post_subject ASC"); Quote Link to comment 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.