Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get the month in mysql

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to get the month in mysql, which can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

In mysql, you can use the MONTH () function to get the month, which gets the month value from the specified date value. The MONTH () function takes a date argument with the syntax format "MONTH (date);" and returns the month corresponding to the specified date, with a range of "1q12".

The MONTH (date) function in MySQL returns the month corresponding to the specified date, with a range of 1-12.

The MONTH () function takes the date parameter and returns the month of the date.

The syntax format is as follows:

MONTH (date); example:

Use the MONTH () function to return the month in the specified date, and the SQL statement entered and the execution result are shown below.

Mysql > SELECT MONTH ('2020-10-12'); +-+ | MONTH ('0-10-12') | +-+ | 10 | +-+ 1 row in set (2020 sec)

According to the running results, the month corresponding to 2020-10-12 is October.

Expand the data

1. Get the current date-- CURDATE ()

SELECT CURDATE (); or select DATE (CURDATE ()); 2. Get the current time-- NOW ()

SELECT NOW ()

3. Get the current year-- YEAR ()

Select YEAR (CURDATE ())

4. Get the current month-- MONTH ()

Select MONTH (CURDATE ())

5. Get January of that year

Select CONCAT (YEAR (CURDATE ()),'-', '01'); Thank you for reading this article carefully. I hope it is helpful for the editor to share how to get the monthly content in mysql. At the same time, I also hope you can support us, pay attention to the industry information channel, find out if you encounter problems, and learn detailed solutions!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report