I have been trying to fix this issue but could not find a solution to it.
I have a date column as string type . Trying to convert it to timestamp using date_parse but getting the following error.
INVALID_FUNCTION_ARGUMENT: Invalid format: "2021-09-28
21:05:28.272159" is malformed at "21:05:28.272159"
my query is
"date_parse"(a.commitdatetime, '%y-%m-%d %h:%i:%s.%f') commitdatetime
do you have any ideas how to fix this issue? Thanks for your time from now
Please refer to format strings documentation. %y and %h should be substituted with %Y and %H correspondingly:
select date_parse('2021-09-28 21:05:28.272159', '%Y-%m-%d %H:%i:%s.%f');
Output:
_col0
2021-09-28 21:05:28.272
Related
error is : Invalid timestamp: '2/17/2022'
Hi guys, Someone can help me to change STING (dd-mm-yyy) to a Date fomat (yyyy-mm-dd)?
thank you for your time
Try below
select parse_date('%m/%d/%Y', '2/17/2022'), parse_date('%m-%d-%Y', '2-17-2022')
with output
Bigquery cannot parse datetime from a date in spite of providing right format. Dates in my column are of the same format I used in the string:
SELECT EXTRACT(DATE FROM PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%S%z',"2021-03-22T14:00:00-03:00"))
This gives this error:
Failed to parse input string "2021-03-22T14:00:00-03:00"
I am trying to make this work by this answer
You should use %Ez instead of %z as in below
SELECT EXTRACT(DATE FROM PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%S%Ez',"2021-03-22T14:00:00-03:00"))
See Supported format elements for TIMESTAMP for more details
I was trying to convert a timestamp string with the following format into a timestamp format but encountered an error as such:
Invalid format: "20201216T090000+0000" is malformed at "0000+0000"
Original Query
SELECT from_iso8601_timestamp(date_ts)
FROM
...
I thought of applying substr to retrieve 20121216T09 only as a string, which I know would work with from_iso8601_timestamp. But any other advice would be appreciated!
The from_iso8601_timestamp() supports format with dashes and colons:
presto> SELECT from_iso8601_timestamp('2020-12-16T09:00:00+00:00');
_col0
-----------------------------
2020-12-16 09:00:00.000 UTC
In the case input is formatted like 20201216T090000+0000, the parse_datetime() would be more appropriate.
I am trying to convert a timestamp string to timestamp with date_parse, but keep getting an error. Any suggestions? I am working on Presto SQL. I have tried to replace %H:%f with %T and it still doesn't work.
date_parse(sg."#timestamp", '%Y-%m-%d %H:%f')
The error message is:
presto: query failed (200 OK): "USER_ERROR: com.facebook.presto.spi.PrestoException: Invalid format: "2017-12-31 08:29:02.12" is malformed at ":02.12""
Any help would be greatly appreciated, thanks!
You need date_parse() with this format:
presto:default> SELECT date_parse('2017-12-31 08:29:02.12', '%Y-%m-%d %H:%i:%S.%f');
_col0
-------------------------
2017-12-31 08:29:02.120
(1 row)
I am trying to parse using the format_date("%m/%d/%Y %H:%M:%S", CURRENT_DATETIME()) as date_mod but it gives me error:
No matching signature for function FORMAT_DATE for argument types: STRING, DATETIME. Supported signature: FORMAT_DATE(STRING, DATE) at [2:9]
I used the FORMAT_DATETIME, without result.
Help pls.
Thx!
As indicated in the error message that you are getting, FORMAT_DATE() is there to format values of the DATE datatype.
If you have a DATETIME (which CURRENT_DATETIME() returns), then you want FORMAT_DATETIME():
format_datetime("%m/%d/%Y %H:%M:%S", CURRENT_DATETIME())