Jump to content

how would less than and greater than be used in a mysql query?


dbradbury

Recommended Posts

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

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());

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

 

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

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");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.