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

前端 未结 6 2136
天涯浪人
天涯浪人 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:25

    There should also be a YEAR().

    As for comparing, you could compare dates that are the first days of those years and months, or you could convert the year/month pair into a number suitable for comparison (i.e. bigger = later). (Exercise left to the reader. For hints, read about the ISO date format.)

    Or you could use multiple comparisons (i.e. years first, then months).

提交回复
热议问题