Forum Moderators: open

Message Too Old, No Replies

Query date range

Two dates in my DB

         

Alternative Future

6:08 pm on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MySQL 5.0

Hi all,

I apologise for this question cropping up again, but I cannot seem to find any threads that cover this particular question.

I have two date fields in my database table a from_date and a to_date the type is DATE and FORMAT is 0000-00-00 yyyy-mm-dd.

My action class that deals with setting up the query accepts the query as two strings in the format 0000-00-00 yyyy-mm-dd my sql query looks like this:
SELECT * from myTable WHERE from_date BETWEEN 'fromDate' AND 'toDate'
I cannot seem to get this to work. Do I have to pass the string dates in as DATE format?
Also how can I make the query also check the to_date?

If I have a deal on between 2006-05-01 (from_date) and 2006-06-31 (to_date) the above query would only check my from_date field and not to_date. I need to find all results between a date range.

I think I am way off what I am trying to do, can someone please help me out...

TIA,

-george

aspdaddy

9:04 pm on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try coverting your inputs to the above format and querying like this.

Where (from_date >= 'fromDate') AND
(from_date <='toDate')

If it doesnt work post the actual SQL generated.

Alternative Future

9:22 pm on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks aspdaddy,

I have it kinda working the suggested way. Still a few bugs to iron out will keep you posted...

-george