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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.