Date column stores date in Y-m-d format i'e 2010-02-25 Is it possible to select records using only a part of the date(year and month) Select * FROM table where date ='2010-02' -- exclude date and get all records for Feb,2010 I dont want to use between and < > operaters
You can do something like this. Select * FROM table where MONTH(date) ='02' AND YEAR(date) = '2010'; Just fyi, this will not allow you to use an index on the date column in case there is one. Also, assuming that this is MySQL. For MSSQL you would need another function.
parsed the date to string use to_char function Select * FROM table where to_char(date,'yyyymm') ='201002' Code (markup):