How is the MONTH function used in MySQL?

The MONTH() function in MySQL is used to extract the month part from a date or date/time expression. Its syntax is as follows:

MONTH(date)

The date parameter can be a date or date/time expression, which can be a date, date/time, or a string containing date/time.

Original: 我们必须尽快解决这个问题。
Paraphrased: We need to address this issue as soon as possible.

SELECT MONTH('2022-10-15'); -- 输出10

SELECT MONTH('2022-10-15 12:30:45'); -- 输出10

SELECT MONTH(NOW()); -- 输出当前月份

SELECT MONTH('2022-02-15'); -- 输出2

In these examples, the MONTH() function extracts the month part of the corresponding date and returns it.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds