How to get month name from date in Presto
Asked Answered
S

3

5

I use Presto and I do not know the function to get MONTH's name from a date column. I can get MONTH number using MONTH(<date>) function but I'm not able to get MONTH name.

I've seen ways where a list of month names is manually created and the number is matched over with the list to obtain the name. Is there a better approach to use any known function in Presto?

Silici answered 20/11, 2017 at 18:44 Comment(2)
Any reason why it's a -1 for the question? I guess I've given details in the question after doing research.Silici
Please specify any code you have. From documentation, prestodb.io/docs/current/functions/datetime.html, there is the %M specifier that should do what you want.Gregoriagregorian
K
5

As commented, Presto provides date_format function which is compatible with MySQL one. %M will tell you the exact month name of your timestamp. For example:

SELECT date_format(timestamp '2017-11-21 12:00:00', '%M') month_name
Katleen answered 24/11, 2017 at 6:37 Comment(0)
S
3

Using Presto , you can also use following function: -

SELECT extract(MONTH from CURRENT_DATE) Month

And Output would look like:-

example

Shipshape answered 10/10, 2019 at 19:13 Comment(0)
C
0

You can also use the date_trunc function

SELECT date_trunc('month', date) as Month

Concubinage answered 12/5, 2023 at 0:11 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Crispas

© 2022 - 2024 — McMap. All rights reserved.