I am pulling the close date from a json field using:
data->>'closeDate' as PortalCloseDate however this returns a string and I am trying to convert it to a date format. The date format in the string is YYYY-MM-DD so I tried (data->>'closeDate')::date but am getting the error: "ERROR: invalid input syntax for type date: "2020-12-09"" Any help is appreciated, thanks!
Try bruteforcing on cleaning and casting the string to date:
select
cast(replace(cast(data->>'closeDate' as varchar), '"','') as date) as "closeDate"
from table
Related
I am trying to convert string to timestamp but haven't been successful.
My field (payment_at) string contains
01-10-2021 9:04:06
01-10-2021 11:48:19
01-10-2021 16:01:35
I tried convert using
PARSE_TIMESTAMP("%Y-%m-%d %H:%M", payment_at)
and
CAST(payment_at AS TIMESTAMP)
but it shows error
Error running query; Invalid timestamp
Please help if I am doing anything wrong
Thankyou!
The format_string your provided does not match the timestamp string input.
Replace "%Y-%m-%d %H:%M" with "%d-%m-%Y %H:%M:%S"
Documentation for the parse_timestamp function:
https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#parse_timestamp
Documentation for supported format elements:
https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#supported_format_elements_for_timestamp
Try this one:
SELECT PARSE_TIMESTAMP("%d-%m-%Y %H:%M:%S", "01-10-2021 11:48:19")
Documentation
I have a table t_am_chat and from this table I use column Date_creat --> Format String in this format 2020-01-01T02:39:45
Goal is transfer to date type DateTime, ideal in format yyyy.mm.dd hh:mm:ss
Any tips please? Thanks.
Vasku, try this:
CDate(Replace(Date_creat,"T"," "))
To test it put copy this to Immediate window of VBE:
?CDate(Replace("2020-01-01T02:39:45","T"," " ))
After hitting Enter you should get this result:
1/1/2020 2:39:45 AM
Could anyone point what to read, because I'm stuck with trivial issue. I store data in JSON format and I have a key with string that consists of a non ISO format datetime value, e.g. '%d-%m-%Y %H:%i:%S'
I've tried function STR_TO_DATE on string "17-12-2019 13:49:50" and it returned SQL datetime result, but when I use it in function
DELETE FROM queue WHERE
ts = CASE
WHEN type = 'entry' THEN HOUR(TIMEDIFF (NOW(), STR_TO_DATE(JSON_EXTRACT(request, "$.date_event"),'%d-%m-%Y %H:%i:%S'))) > 72
SQL raises
Incorrect datetime value: '"07-12-2016 18:21:59"' for function
str_to_date
When I try statement SELECT STR_TO_DATE(JSON_EXTRACT(request, "$.date_event"),'%d-%m-%Y %H:%i:%S') MySQL returns null
Your issue is caused by the double quotes returned around the extracted value. You need to either unquote the extracted value e.g.
JSON_UNQUOTE(JSON_EXTRACT(request, "$.date_event"))
or using shorthand notation
request->>'$.date_event'
Or add the double quotes into the STR_TO_DATE template i.e.
STR_TO_DATE(JSON_EXTRACT(request, "$.date_event"),'"%d-%m-%Y %H:%i:%S"'))
Demo on dbfiddle
how to convert a string of format'2019-09-01T02:55:10.000Z' to date in plsql?
I tried converting using to date function but it doesn't work
Try:
TO_DATE('2019-09-01T02:55:10.000Z', 'YYYY-MM-DDThh:mm:ss.fffTZD')
I am trying to update a datetime which is in String format YYYYMMDDHHMMSSZ into YYYY-MM-DD HH:MM:SS.
I was trying to run a query: Update consolidated_table SET createtimestamp_E=DATE_FORMAT(createtimestamp_E, '%Y-%m-%d %T') but getting:
Error Code: 1292`. Incorrect datetime value: ''
I tried inserting the csv file in datetime format, but that didn't work.
So I had to upload it in String format and now I'm trying to convert the string into date format, but in vein.
I was able to get this issue fixed by using below command:
SUBSTRING(#var, 1, CHAR_LENGTH(#var)-1).
I further wanted to convert this column from string to datetime for which i used the below command:
SET createtimestamp=CONVERT (SUBSTRING(#var, 1, CHAR_LENGTH(#var)-1),DATETIME)