mdvignesh Posted March 20, 2012 Share Posted March 20, 2012 I am having date column with date datatype like this 2012-03-01 2012-03-02 2012-03-03 2012-03-04 2012-04-01 2012-04-02 2012-05-01 2012-05-02 How to select all fields of march month?? Quote Link to comment Share on other sites More sharing options...
samshel Posted March 20, 2012 Share Posted March 20, 2012 Check this : http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format something like the following should give you what you want: SELECT * FROM tbl_name WHERE date_format(dt, '%m') = 3 Change the table name and field names accordingly. Quote Link to comment Share on other sites More sharing options...
batwimp Posted March 20, 2012 Share Posted March 20, 2012 You could also try: SELECT * FROM tbl_name WHERE month(date_column) = 3 Quote Link to comment Share on other sites More sharing options...
kicken Posted March 20, 2012 Share Posted March 20, 2012 Note that unless you want the records from all years, you'll want to add a year constraint on that as well, such as: SELECT * FROM tbl_name WHERE MONTH(col)=3 AND YEAR(col)=2012 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.