0

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....

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by mitmehta22
0

Have you consider using the between keyword?

SELECT columns
FROM tables
WHERE column1 between value1 and value2;

0

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"

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.