i am using MySQL database. i have one field PurchaseDate. i want following result

e.g. : PurchaseDate between May-2010 and Aug-2011

pls help me to solve this problem. its urgent. thanks in advance....

Have you consider using the between keyword?

SELECT columns
FROM tables
WHERE column1 between value1 and value2;

yes i have tried between keyword but its not working because i want to filter only month & year. if full date is given then no problem but when i give only month and year, it is retieving records but they are not in range. i have also tried month(), year() and date_format() functions.
my sql is like follow:

select date_format(purchasedate,'%d-%M-%Y') from purchase
where date_format(purchasedate,'%m-%y') between "05-2010" and "08-2011"

i have solved my problem. in sql i have added one month.

for ex. i need record between May,2010 and Apr-2012 so the sql is like follow:

Select DATE_FORMAT(PurchaseDate,'%d-%M-%Y') as PurchaseDate
from Purchase
where PurchaseDate >= '2010-5-1' AND PurchaseDate < '2012-5-1'

this should be marked as solved

how can i mark it as solved?

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.