mysql - how to filter based by current year and lastyear? -
i have table year values ('2013','2014','2015','2016')
i want filter values current year , last year results of searching current yea , last year ('2016','2015') how filter based current year , lastyear?
you can use year()
function:
where col in (year(curdate()), year(curdate()) - 1)
however, if column contains strings, should convert these strings performance reasons:
where col in (date_format(curdate(), '%y'), date_format(date_sub(curdate(), interval 1 year), '%y') )
Comments
Post a Comment