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 Link to comment https://forums.phpfreaks.com/topic/223288-how-would-less-than-and-greater-than-be-used-in-a-mysql-query/ 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()); Link to comment https://forums.phpfreaks.com/topic/223288-how-would-less-than-and-greater-than-be-used-in-a-mysql-query/#findComment-1154341 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? Link to comment https://forums.phpfreaks.com/topic/223288-how-would-less-than-and-greater-than-be-used-in-a-mysql-query/#findComment-1154348 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 Link to comment https://forums.phpfreaks.com/topic/223288-how-would-less-than-and-greater-than-be-used-in-a-mysql-query/#findComment-1154353 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 Link to comment https://forums.phpfreaks.com/topic/223288-how-would-less-than-and-greater-than-be-used-in-a-mysql-query/#findComment-1154358 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"); Link to comment https://forums.phpfreaks.com/topic/223288-how-would-less-than-and-greater-than-be-used-in-a-mysql-query/#findComment-1154361 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"); Link to comment https://forums.phpfreaks.com/topic/223288-how-would-less-than-and-greater-than-be-used-in-a-mysql-query/#findComment-1154372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.