June 23rd, 2013, 01:55 PM
Originally Posted by giridhar276
Here the problem is I am going to pass any two months from the web interface to the backend mysql database.
The problem is what r937 already said: Your way of storing time information is totally inappropriate.
MySQL doesn't know that your "march" comes after "january", so every time you wanna select a time range, you first have to build a complete list of month names -- which is a disaster. Things get even worse if your range covers multiple years. Then you'll end up with monstrosities like
p_month IN ('october', 'november', 'december')
AND p_year = 2011
OR p_year IN (2012, 2013)
p_month IN ('january', 'february', 'march', 'april')
AND p_year = 2014
Simply use DATEs
with the day set to the first of the month. Then you can use the standard comparison functions without any need for weird workarounds.