Hi,
i would like to convert string to date data type on Athena.
createdate = 2023-03-16T16:54:59.000+0000
1 i’m split to 2023-01-23
2 i’m need to convert string to date format 2023-01-23
3 this is my sql
select
date_parse(concat(SUBSTRING(ap.createddate, 1, 4),‘-’,SUBSTRING(ap.createddate, 6, 2),‘-’,SUBSTRING(ap.createddate, 9, 2)),‘%Y-%M-%d’) as date3
Hi Max,
i’ve write sql as you suggest. however i got an error.
select
CAST(ap.createddate AS TIMESTAMP)
region:
ap-southeast-1
timestamp:
1681138089793
requestId:
01066b56-776d-4d5c-b69a-2955723cf6b5
sourceErrorCode:
100071
sourceErrorMessage:
[Simba]AthenaJDBC An error has been thrown from the AWS Athena client. COLUMN_NOT_FOUND: line 2:300: Column ‘_col4’ cannot be resolved [Execution ID: a659c610-9bc8-4127-a5e6-f927941a87f0]
i already name it , but still error , it look like value can’t be cast.
createdate = 2023-03-16T16:54:59.000+0000
region:
ap-southeast-1
timestamp:
1681141748291
requestId:
96836e8e-7ca5-41a3-ac99-84533ff51c99
sourceErrorCode:
100071
sourceErrorMessage:
[Simba]AthenaJDBC An error has been thrown from the AWS Athena client. INVALID_CAST_ARGUMENT: Value cannot be cast to timestamp: 2023-03-16T16:54:59.000+0000 [Execution ID: 4d1e9c84-e0fe-457e-adb2-0f8532fba314]
Hello @thomask thank you for your comment. I tried it out, but it does not work for me, I am getting the following error: [HY000][100071] [Simba]AthenaJDBC An error has been thrown from the AWS Athena client. FUNCTION_NOT_FOUND: line 4:12: Unexpected parameters (timestamp(3), integer, integer) for function substring. Expected: substring(varchar(x), bigint, bigint), substring(varchar(x), bigint), substring(char(x), bigint), substring(char(x), bigint, bigint) [Execution ID: d47c3fc7-6fb2-4db6-a0c3-01aa8268f473]