How do I extract Month and Year in a MySQL date and compare them?

前端 未结 6 2140
天涯浪人
天涯浪人 2020-12-05 22:51

How do I extract the month and date from a mySQL date and compare it to another date?

I found this MONTH() but it only gets the month. I looking for month and year.<

6条回答
  •  粉色の甜心
    2020-12-05 23:04

    If you are comparing between dates, extract the full date for comparison. If you are comparing the years and months only, use

    SELECT YEAR(date) AS 'year', MONTH(date) AS 'month'
     FROM Table Where Condition = 'Condition';
    

提交回复
热议问题