简体   繁体   English

在 Athena AWS SQL 中将字符串转换为日期类型

[英]Convert string to date type in Athena AWS SQL

I have a column that called date with the following format: '20220816' how can I convert this column into Date format?我有一个名为 date 的列,格式如下:'20220816' 如何将此列转换为日期格式?

I tried to use this function: date_parse(date,'%y/%m/%d') but it keep giving me this error: NVALID_FUNCTION_ARGUMENT: Invalid format: "20220627" is malformed at "220627"我试图使用这个 function: date_parse(date,'%y/%m/%d') 但它一直给我这个错误: NVALID_FUNCTION_ARGUMENT: Invalid format: "20220627" is malformed at "220627"

You have to remove the slashes from your query.您必须从查询中删除斜杠。 Below query convert it to date format for you.下面的查询为您将其转换为日期格式。 Just replace the string with the column containing values只需将字符串替换为包含值的列

select cast(date_parse('20220816','%Y%m%d') as date)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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