I have a table with a varchar field called slldate. This field contains dates in this format:
2010-08-30
(YYYY-MM-DD)
Now I would like to select the records containing the current month using a mysql query.
Anyone?
as you used a char field instead a date field, you have to cast the value and then use the normal date functions. like
SELECT * FROM table WHERE MONTH(CAST(slidate as date)) = MONTH(NOW()) AND YEAR(CAST(slidate as date)) = YEAR(NOW())
Try this:
SELECT * FROM table_name WHERE MONTH(slldate) = date('m') AND YEAR(slldate) = date('Y');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With