[thelist] date selection and mysql and PHP

Getafixx getafixx at getafixx.com
Mon May 9 13:19:51 CDT 2005


OK I am working on a simple calender (OK I know it's pretty dull stuff)

My questions are - I am storing the date and the timing of an event with 
DATETIME, which seams to work OK.

I have been trying to craft a search to get ONLY the events on the day 
in question.. The only way I could do that and it was a big hack was to 
use this query, where I have to arse around with figuring out what the 
next day is and go from the correct day to the next day...

SELECT * FROM `events` WHERE `date_time` BETWEEN "20050509" AND 
"20050510" ORDER BY "20050509"

I don't like this because I don't want to have to write loads of code to 
check that the next day (ie just making day ++) is still a valid day, 
and by this time I have broken down (OK on having written this line, I 
think of a few more ways I could do that.. )

Maybe my question is why can't I just say where date row = <my date> 
where I try and match just the first part of the date with the first 
part of any dates in the table

SELECT * FROM `my_table` WHERE `date_time` = "20050509"

but this doesnt seam to work...

Any ideas? or am I doing it right?

Also on reading the db for a months worth of dates, would it be better 
to do one query for the whole month and then parse it up, or lots of 
small queries, for each day?

Thanks in advance.

Justin


-- 
==============================================================
Justin / Getafixx                                07967 638 529
mailto:qwerty1 at getafixx.com

http://getafixx.com
http://getafixxhosting.com for really cheap web hosting
==============================================================



More information about the thelist mailing list