Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates and ... logic (...I guess)

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
Hello,

I am trying to make it possible to have a user
select a date with two selects menus (one for the day and another
one for the month) what would trigger a query which will search for
rows where the choosen date is chronologically between a starting date
(column called "dep_from") and an ending date (column called "dep_to").

Those two columns are date formatted (0000-00-00).
I had a long look to the mysql documentation (date&time functions)
but I didn't find such a function.
I have found the "BETWEEN" command in the TEK-TIPS forum but what I've
done with it refuses to work properly.
Would someone be kind enough to tell me what is going wrong?

Here is what I did:

$choice1_dep = "2001-" . $dep_month_1 . "-" . $dep_day_1;

$db = mysql_connect("localhost", "xxxx", "xxxx");
mysql_select_db("xxxx",$db);

$sql="SELECT * FROM table WHERE ($choice1_dep BETWEEN dep_from AND dep_to)";

If someone has a better idea than "BETWEEN" (but not too complicated!!!) I wish
he tells me.

Have a good day.
 
Have you tried this:
Code:
$sql = "SELECT *";
$sql .= " FROM table";
$sql .= &quot; WHERE ((dep_from<'&quot;.$choice1_dep.&quot;')&quot;;
$sql .= &quot; AND (dep_to>'&quot;.$choice1_dep.&quot;'))&quot;;
I don't know about
Code:
BETWEEN
(which may be more elegant), but I'd hazard that the above code will do the job.

-Rob
 
Dear Rob,

Your guess was 100% right! I am sure it's more thanks
to your experience than a simple hazard like you said.
THANKS A LOT for your help, really.

I don't quite understand why I have to do like you did
but I am going to try to find out quickly.

Thanks a again and have a good day.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top