Hello,

I am doing some search in which my requirment is to search between specific dates.
Like user can put start date and then end date. Once submit then it should find result between these two dates.

Select from table where date1>2001-01-05 And date2< 2001-02-05.

Will this above statement will work. Is there any function which subtracts date like this. How mysql function works when we use query like date less than 2001-01-05

thanks

Recommended Answers

All 13 Replies

I have not checked your query. But this will work.

$query="select * from table where date_column between "2001-01-05" and "2001-01-10";

This will print all the records where the date_column value lies between the first date and the second date.

Okay! I checked this and even this works. Select * from tables where CREATE_TIME > "2008-02-01" and CREATE_TIME < "2008-02-08" Cheers,
Naveen

thanks mate. I think this query will work.

You are welcome! :)
Btw, If your problem is solved, you can mark this thread as solved.

What if I want to query between a date in August and a date in September. I've tried this and it doesn't work:

$query = "SELECT Date FROM test WHERE Date >= '28/08/2010' AND Date <= '02/09/2010'";

Thanks in advance

If you want to search two dates between php or mysql then there are so many advance facility will be available for searches the dates in php that can provide so many advance facility it into them.

What if I want to query between a date in August and a date in September. I've tried this and it doesn't work:

$query = "SELECT Date FROM test WHERE Date >= '28/08/2010' AND Date <= '02/09/2010'";

Thanks in advance

from what I know Mysql uses the year-month-day format try sending :

$query = "SELECT Date FROM test WHERE Date >= '2010/08/28' AND Date <= '2010/09/02'";

I tried "SELECT NOW()>= '2012/01/28' AND NOW() <= '2012/03/02'" now was equal to 2012-02-08 10:59:43 and it returned 1

Would the following line work for a varchar db field called 'date' using mm/dd/yyyy format ??? I'm trying to accomplish the same thing and am pretty limited to using a mm/dd/yyyy format.

$query = "SELECT * FROM $table WHERE Date >= '08/28/2010' AND Date <= '09/02/2010'";

$query = "SELECT Date FROM test WHERE Date >= '2010/08/28' AND Date <= '2010/09/02'";

its easy to seach through the mysql than using the php

Member Avatar for angiesavio

i want to search date greater than particular date but my date column datatype in text,
SELECT * from $table Where postedDate>='21-August-2013' and postedDate<='22-August-2013' ORDER BY modified_date DESC
this not working properly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.