Search code examples
phpmysqlsubstr

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


Is there any method to solve this problem ? in mysql column field date is value as timestamp and i want to fetch all row date which has specific value as format Y-mm ( 2016-05 )? please help me i am stacking in this problem, Is it possible ?

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

Solution

  • Try 'date_format()' mysql function:

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