(Presto)Amazon Athena Convert String to Date - presto

I would like to set the date to YYYYY-MM-01. How can I fix this error?
Please help me..
The error SQL:
select DATE_parse('2022-05-21','%Y-%m-01') as YYYYMM from tb1;
The error text :
INVALID_FUNCTION_ARGUMENT: Invalid format: "2022-05-21" is malformed at "21"

Self resolved.
select DATE_ADD('day', 0, date_trunc('month', date(cast('2022-05-21' as date)))) from tb1;

Try this:
select cast(concat(substr('2022-05-21',1, 7), '-01') as date)

Related

MOMENTJS TIME FORMATTING

I have this data :
time: "2020-12-17T13:06:13.144Z"
and then I want change this data, to be like this...
"17-12-2020 13:06:13"
but when I change with this code:
{moment(time).format("DD-MM-YYYY HH:mm:ss")}
MY OUTPUT IS NOW :
"17-12-2020 20:06:13"
MY OUTPUT EXPECTATION:
"17-12-2020 13:06:13"
How can I change this format so that it matches my expectation?
Try utc() method before format:
moment(time).utc().format("DD-MM-YYYY HH:mm:ss")
You can add custom string in moment format string with [:]
Try this
{moment(time).format("["]DD-MM-YYYY HH:mm:ss["]")}

Passing today's date in soapui with specific format

I want to pass today's date in this format 2020-12-07T20:15:15.783-06:00 by using this groovy script in soapui
${= new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ" )}
But I am getting the following error
Script48.groovy: 1: unexpected char: '' # line 1, column 20.
new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ" )```
Not sure what I am missing ? I want the date format to be matching the example.
Do it like this:
myTimestamp = new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
log.info "${myTimestamp}"

Parse dates with timezone

This works correctly and return "2020-02-01 00:00:01.132 UTC". But if the time zone is part of parse_datetime function, it does not work.
Works:
select parse_datetime('2020-02-01 00:00:01.132000' ,'yyyy-MM-dd'' ''HH:mm:ss.SSSSSS');
Does not work:
select parse_datetime('2020-02-01 00:00:01.132000+5:30' ,'yyyy-MM-dd'' ''HH:mm:ss.SSSSSS''Z');
The error says malformed at "+5:30". How do I parse dates with timezone in athena?
select parse_datetime('2020-02-01 00:00:01.132000+05:30' ,'yyyy-MM-dd'' ''HH:mm:ss.SSSSSSZ');

Sqlite3 conversion MM/DD/YY string to YYYY-MM-DD

I am trying to convert a string column of existing values from 'MM/DD/YY' to 'YYYY/MM/DD'.
Example Data:
Table: backlog_backlogData
[LoadDate]
06/29/18
06/29/18
06/28/18
07/24/18
07/24/18
I have tried this (in SQLite Manager FireFox extention):
UPDATE backlog_backlogData SET LoadDate = substr(LoadDate, 7, 2)||”-“||substr(LoadDate, 1,2)||”-“||substr(LoadDate, 4,2)
Unfortunately, the column is updated with only the first substr (results: 18). It seems like SQLite does not like concatenates ||?
I've searched for an answer and have not found anything that works.
Thanks for you time.
try replacing ” with "
you can check the query with a SELECT statement
SELECT substr(LoadDate, 7, 2)||"-"||
substr(LoadDate, 1,2)||"-"||
substr(LoadDate, 4,2)
from backlog_backlogData
example using python to convert date table column
I'm confident it was an issue with the SQLite Manager Firefox Extension. I ran the following code from cursor in python and it worked:
UPDATE backlog_backlogData SET LoadDate = substr(LoadDate, 7, 2) || '-' || substr(LoadDate, 1,2) || '-' || substr(LoadDate, 4,2)
I then reset my data and reran the code within the SQLite Manager Extension and it only processed the code up to the first concat.
EDIT: Thanks for the help below!

dbSendquery giving format error

I need to create a table and insert some values into it uisng r
library(sqldf)
Company_Master <- dbConnect(SQLite(), dbname="Company Master.sqlite" )
dbSendQuery(conn = Company_Master,
"CREATE TABLE Company Master(
Comp_name varchar
Address varchar)
")
Till here no error is given.But after this when i want to insert some value into the table
dbSendQuery(conn = Company_Master, "INSERT INTO COMPANY MASTER
VALUES('INFOSYS','abcLALA')")
I get error like
Error in result_create(conn#ptr, statement) : near "Master": syntax error
I found the format on https://www.r-bloggers.com/r-and-sqlite-part-1/ and don't seem to get any other format except if using dbCEATETABLE. What is wrong in this format? Please help

Resources