Alex Rivera | Logout

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

Asked 2011-10-20T03:57:59.450
90

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.

Edit
Report

1 Answer

1

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).

answered 2011-10-20T04:03:15.673

Your Answer