SELECT sales_invoice_date,
MONTH( DATE_TRUNC('month',
CASE
WHEN TRIM(sales_invoice_date) = '' THEN
DATE('1999-12-31')
ELSE
DATE_PARSE(sales_invoice_date, '%m/%d/%Y')
END) ) AS DT
FROM testdata_parquet
I used the query above to convert the string into date and was able to get the month number on AWS athena but I wasn't able to get the corresponding month name
I have already tried monthname
and datename('month', ...)
but they gave the following error messages respectively:
SYNTAX_ERROR: line 2:1: Function monthname not registered
SYNTAX_ERROR: line 2:1: Function datename not registered
To convert data in arrays to supported data types, use the CAST operator, as CAST(value AS type) . Athena supports all of the native Presto data types. To use the Amazon Web Services Documentation, Javascript must be enabled.
Q: What data formats does Amazon Athena support? Amazon Athena supports a wide variety of data formats like CSV, TSV, JSON, or Textfiles and also supports open source columnar formats such as Apache ORC and Apache Parquet. Athena also supports compressed data in Snappy, Zlib, LZO, and GZIP formats.
When you use CREATE_TABLE , Athena defines a STRUCT in it, populates it with data, and creates the ROW data type for you, for each row in the dataset. The underlying ROW data type consists of named fields of any supported SQL data types.
Athena is currently based on Presto .172, so you should refer to https://trino.io/docs/0.172/functions/datetime.html for available functions on date/time values.
You can get month name with date_format()
:
date_format(value, '%M')
or similarly format_datetime()
.
format_datetime(value, 'MMM')
Example:
presto:default> SELECT date_format(current_date, '%M');
_col0
----------
December
(1 row)
(verified on Presto 327, but will work in Athena too)
You can use to_char()
function with 'month'
argument :
to_char(sales_invoice_date, 'month')
in order to return the month names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With