...

View Full Version : compare date problem



maxpouliot
08-03-2006, 03:55 PM
In a table, i have two date fields (startDate, endDate)

I want to make a query that checks if two date that i entered in a form (date1,date2) is between the two dates dates in my table.

date1 = 2006-08-01
date2 = 2006-08-31

I thought something like this would work but it doesnt... can anybidy help me?

SELECT typeFormation, startDate, endDate FROM formations WHERE (date1>=startDate AND date1 <= endDate) OR (date2>=startDate AND date2 <= endDate)

Fumigator
08-03-2006, 05:30 PM
The example you give should work fine. Alternatively, you can use the "between" keyword.

http://dev.mysql.com/doc/refman/4.1/en/comparison-operators.html

guelphdad
08-03-2006, 08:41 PM
Is the date type of your startdate and enddate columns acutally a DATE type? If it isn't but is a varchar or a char then you may not be able to return correct results.

also have you tried hard coding your values that are being passed from the form just to make sure those are being passed correctly?

Fumigator
08-03-2006, 11:45 PM
Is the date type of your startdate and enddate columns acutally a DATE type?

That is a really good question-- could be the whole problem right there. I just assumed the columns are date types.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum