Page 1 of 1

search db by date

Posted: Wed Dec 07, 2005 7:09 am
by ddragas
$datum = time();

All entries in db in field 'date' are inserted with value of $datum at the time of inserting into db

Is folowing code correct to search db in column 'date' where 'date' = '21.10.2005'

Code: Select all

$datum = $_POST['pojam'];

				 include("../stranice/con_db.php");

				$result = mysql_query("select * from $table_name where 
				date = date("d.m.Y ",  $datum)") or
				die (mysql_error());
	
					while($row = mysql_fetch_array($result))
						{

							etc......

Re: search db by date

Posted: Wed Dec 07, 2005 7:15 am
by foobar
You have a syntax error there, and a semantic error.

This:

Code: Select all

mysql_query("select * from $table_name where date = date("d.m.Y ",  $datum)")
should be:

Code: Select all

mysql_query("select * from $table_name where date = '".date("d.m.Y ",  $datum)."'")
Assuming your date field is of type text, blob or varchar.

Posted: Wed Dec 07, 2005 7:24 am
by ddragas
THANK YOU

Posted: Wed Dec 07, 2005 1:05 pm
by Luke
I don't understand why people don't just use timestamps in databases... ??

Posted: Wed Dec 07, 2005 1:59 pm
by twigletmac
The Ninja Space Goat wrote:I don't understand why people don't just use timestamps in databases... ??
Or the databases own DATE field type - makes calculations and formatting of dates much easier.

Mac

Posted: Wed Dec 07, 2005 3:43 pm
by Ambush Commander
TIMESTAMP really isn't a unix timestamp.

Posted: Wed Dec 07, 2005 3:45 pm
by Burrito
DATE or DATETIME fields are the way to go...

Posted: Wed Dec 07, 2005 4:00 pm
by Luke
the only advantage date/datetime has over a timestamp in my opinion is that they are human-readable if you are looking at them in phpmyadmin or something.