MySQL MONTHNAME() 来自数字

2021-11-20 00:00:00 mysql

无论如何可以从月份(1-12)中获得MONTHNAME()?例如,如果我有 6,7,8,MySQL 中是否有任何本地方式将它们转换为 June,July,August?

Is there anyway to get the MONTHNAME() from just the number of the month (1-12)? For example if I have 6,7,8 is there any native way in MySQL to transform those into June,July,August?

推荐答案

您可以使用 STR_TO_DATE() 将数字转换为日期,然后返回 MONTHNAME()

SELECT MONTHNAME(STR_TO_DATE(6, '%m'));

+---------------------------------+
| MONTHNAME(STR_TO_DATE(6, '%m')) |
+---------------------------------+
| June                            |
+---------------------------------+

警告:如果在很多行上完成,这可能会很慢.

Warning: This could be slow if done over a lot of rows.

相关文章