mysql 代码 有什么方法可以解决这个问题吗?子字段列

mysql code Is there any method to solve this ? substr field column

有什么方法可以解决这个问题吗? 在 mysql 列字段中,日期的值是时间戳,我想获取所有具有特定值的行日期,格式为 Y-mm ( 2016-05 )? 请帮助我解决这个问题,有可能吗?

select * from article where postby = 'admin' AND substr(`date`,0,7) = '2016-05'

尝试“date_format()”mysql 功能:

select * from article where postby = 'admin' AND date_format(`date`,'%Y-%m') = '2016-05'

如果必须使用 SUBSTR,请先尝试 CAST

SELECT * FROM article WHERE postby = 'admin' 
AND SUBSTR(CAST(`date` AS CHAR(10)),0,7) = '2016-05'