Jump to content


Photo

date comparision --- wrong file type / format?


  • Please log in to reply
4 replies to this topic

#1 spooooky

spooooky
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 April 2003 - 06:18 PM

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



?>





#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 21 April 2003 - 06:21 PM

What are u trying to do

are u trying to compare two dates and fine the result??

can u be a little clear!
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 21 April 2003 - 06:33 PM

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..._Foramt/138.php
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#4 spooooky

spooooky
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 April 2003 - 07:39 PM

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

#5 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 21 April 2003 - 07:47 PM

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)

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users