spooooky Posted April 21, 2003 Share Posted April 21, 2003 Hi folks! I´m desperate. I\'m trying to compare dates from a user input (drop down menu) with those of a mysql DB in \"date\" format. I force the user input to be the same format (YYYY-MM-DD) as those in my DB. I tried all kinds of combinations of \"<>=\", sometimes i get all results, sometimes none and sometimes only those that dont even have a date (then 0000-00-00). What am I doing wrong?! thx in advance! your site did already help me out often enough! <?php $filter=$_POST[\'checkboxes\']; // Zuweisung der Auswahl aus "filtercheck_DHR.php" to array $andtime=$_POST[\'zeit\']; if ($andtime) { $D=$_POST[\'tag\']; // format of \'tag\': XX $M=$_POST[\'monat\']; // format of \'monat\': XX $Y=$_POST[\'jahr\']; // format of \'jahr\': XXXX $help="$Y-$M-$D"; $date="Von <= $help <= Bis"; // sql query part in var $date // (for timecheck: $help should lie in between start and end date of matching offers) // "Von" and "Bis" in \'date\' file type } $count=count($_POST[\'checkboxes\']); switch($count) { // sql query part for var $cat case 1: $cat="Angebotskategorie=\'$filter[0]\'"; break; case 2: $cat="Angebotskategorie=\'$filter[0]\' OR Angebotskategorie=\'$filter[1]\'"; break; case 3: $cat="Angebotskategorie=\'$filter[0]\' OR Angebotskategorie=\'$filter[1]\' OR Angebotskategorie=\'$filter[2]\'"; break; case 4: ... } $select="SELECT * FROM Angebot WHERE "; $order="ORDER BY Angebotskategorie"; if ($andtime) { // $sql="$select ($date) AND ($cat)"; } else { $sql="$select $cat $order"; } echo ($sql); $link_id=mysql_connect("localhost","....") or die("keine Verbindung"); // DB connection mysql_select_db("0251_reiseshop") or die("Datenbankauswahl nicht möglich"); $result=mysql_query($sql, $link_id); // SQL query if ($result) { // output results $number=mysql_num_rows($result); echo "Ihre Auswahl liefert $number Ergebnis(se)"; echo "<TABLE BORDER=1>"; while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<TR><TD>"; echo implode("<TD>",$row); echo "</TR>"; } echo "</TABLE>"; } else { echo "<P>".mysql_error($link_id); } mysql_close($link_id); // DB disconnection ?> Quote Link to comment https://forums.phpfreaks.com/topic/379-date-comparision-wrong-file-type-format/ Share on other sites More sharing options...
shivabharat Posted April 21, 2003 Share Posted April 21, 2003 What are u trying to do are u trying to compare two dates and fine the result?? can u be a little clear! Quote Link to comment https://forums.phpfreaks.com/topic/379-date-comparision-wrong-file-type-format/#findComment-1282 Share on other sites More sharing options...
shivabharat Posted April 21, 2003 Share Posted April 21, 2003 Have a look at this link this code will help u in getting the date difference in HH:MM:SS but I am sure this will give u an idea http://www.phpfreaks.com/quickcode/Getting..._Foramt/138.php Quote Link to comment https://forums.phpfreaks.com/topic/379-date-comparision-wrong-file-type-format/#findComment-1283 Share on other sites More sharing options...
spooooky Posted April 21, 2003 Author Share Posted April 21, 2003 it´s supposed to be kind of a search function. u select different categories and a date and then u get several results. in my case those results are mostly events or sth. so they have a start date and an end date. my search function works perfect without date selected. but anyway the user should be able to select also by date. so he chooses a date from my drop down menu and only those results should be returned, that match the categories AND the selected user date must be in between the start and end date of those results. i try to handle this with the sql query: SELECT * FROM Angebot WHERE Von <= $help <= Bis AND Angebotskategorie=\'$filter[0]\' OR Angebotskategorie=\'$filter[1]\' OR ... where \"Angebot\" is the event table, \"Von\" the start and \"Bis\" the end date $help is the date selected by user in this format: YYYY-MM-DD Quote Link to comment https://forums.phpfreaks.com/topic/379-date-comparision-wrong-file-type-format/#findComment-1285 Share on other sites More sharing options...
shivabharat Posted April 21, 2003 Share Posted April 21, 2003 so u want to display records based on (from) ( to) what have u defined the filed which has the date is that timestamp or int or varchar?? u can use select * from table_name where date_filed between (start_date) 20021129 and 20021211(enddate) Quote Link to comment https://forums.phpfreaks.com/topic/379-date-comparision-wrong-file-type-format/#findComment-1287 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.