简体   繁体   中英

Date Conversion To Year-Month In Snowflake

I am attempting to convert a date (formatted as yyyy-mm-dd) to a year-month format (ex: 2021-07) while keeping the date datatype.

Coming from SQL Server, this could be done using the FORMAT function like this:

SELECT FORMAT(date_column, 'yyyy-MM')

I am wondering how this could be achieved in SNOWFLAKE . I couldn't find the FORMAT function in SNOWFLAKE so I attempted with DATE, DATE_PART, but they all seem to make my column a varchar, losing its date type.

Thanks.

FORMAT的等价物是TO_VARCHAR

 TO_VARCHAR( <date_or_time_expr> [, '<format>' ] )
SELECT TO_VARCHAR(date_column, 'yyyy-MM')

TO_DATE()这样做,就像TO_DATE(date_column, 'yyyy-MM')https://docs.snowflake.com/en/sql-reference/functions/to_date.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM