PDA

View Full Version : Mysql Between date1 and date2 not working


mafattah
11-06-2004, 02:30 AM
Hi to all,

Iam using php to access mysql database to get the records from the database between two dates.

eg:

i have a column called doj (datetime type) which is storing the date and time in the following format:

2004-12-01 10:56:24 -- date time

in the table.

so i want to access the records in between particular dates.

eg: to get the records having date between 01-01-2004 and 31-01-2004

Iam using the query:

SELECT *
FROM mytable
WHERE doj BETWEEN '2004-01-01' AND '2004-01-31';

but this query is returning all the records in the table instead of returning only records having date between 1st jan and 31st jan........?????????

I could not figure out the problem.....are there problems with the between clause of mysql database...is there any alternate solution to this.....??????

Its URGENT anyone please help>>>>>>>>>>>>>>>>>>>>>>>
:rolleyes:

michiel
06-10-2005, 05:45 AM
Try

SELECT *
FROM mytable
WHERE doj BETWEEN '2004-01-01 00:00:00'' AND '2004-01-31 23:59:59';

:)