Redshift to_timestamp with timezone offset - amazon-web-services

I have difficulties in converting this timestamp string 2020-09-08T15:30:00+00:00 to a correct UTC time:
If I do this:
select to_timestamp('2020-09-08T15:30:00+00:00', 'YYYY-MM-DD"T"HH24:MI:SS');
I get 2020-09-08 15:30:00.000000 -04:00, which is on a wrong timezone.
How can I parse the +00:00 part of the string? I tried TZ/OF based on AWS document but they are not allowed to be added:
[0A000][500310] [Amazon](500310) Invalid operation: "TZ"/"tz" not supported;
, while I'm doing this: select to_timestamp('2020-09-08T15:30:00+00:00', 'YYYY-MM-DD"T"HH24:MI:SS+TZ');

Not sure why you are trying to convert using to_timestamp, because in your example its already UTC/GMT only.
I have used this way in past, I hope it should work for you as well.
#below is something saved in IST(+5:30) to GMT
SELECT CONVERT_TIMEZONE('GMT','2020-09-08 15:30:00+05:30');
Similarly, it could be converted to US/Newyork timezone.
SELECT CONVERT_TIMEZONE('America/New_York','2020-09-08 15:30:00+05:30') ;

Related

Timezone name (like PDT) in date field

I am having trouble with converting a date in PowerBI like:
Column name date:
2022-06-25 05:23:15 PDT
First off, after importing this file into my PowerBI project, the column above
is marked as text. If I try to change this column type to Date/Time/Timezone in the query editor the result in an error:
= Table.AddColumn(#"Promoted Headers", "NewDate", each DateTimeZone.FromText([date]))
DataFormat.Error: We couldn't parse the input provided as a DateTimeZone value.
Details:
2022-06-25 05:23:15 PDT
Is the use of a Timezone name a bad thing in PowerBI? All examples I search for use a UTC offset but the date I have is so common, it seems ridiculous to have to change the data to a UTC offset.
You have to do a conversion I'm afraid. Something like the following I think for PDT.
= Table.AddColumn(Source, "Custom", each DateTime.AddZone( DateTime.FromText([Column1], [Format = "yyyy-MM-dd hh:mm:ss"]), -7))

Prestosql/Amazon Athena: Time Zone Change

I need to change a UTC timestamp to 'US/Eastern' timestamp without changing the date and time - essentially update only the timezone information and later convert that to a different timezone.
For example (what I need):
'2021-06-09 19:00:36.000000' UTC --> '2021-06-09 19:00:36.000000' US/Eastern
Then I need to convert that to 'America/New_York'.
'2021-06-09 19:00:36.000000' US/Eastern --> '2021-06-09 16:00:36.000000' America/Los Angeles
When I try the query below, it's not giving me the correct results, since it is converting from UTC to America/Los Angeles. When it should be US/Eastern to America/Los Angeles.
SELECT id
, date_utc
, CAST(date_utc AT TIME ZONE 'America/Los Angeles') AS date_la
FROM call_records
I'm not sure if this will work for Athena, as it's based on a very old version of Presto/Trino.
In recent versions of Trino (formerly known as PrestoSQL), you can do this:
Cast the timestamp with time zone to timestamp to remove the timezone part.
Then, use with_timezone to reinterpret the resulting timestamp in US/Eastern.
Finally, use AT TIME ZONE to change the time zone of the resulting timestamp with time zone while preserving the instant.
Take a look at the example below:
trino:tiny> WITH t(ts) AS (VALUES TIMESTAMP '2021-06-09 19:00:36.000000 UTC')
-> SELECT with_timezone(cast(ts as timestamp(6)), 'US/Eastern') AT TIME ZONE 'America/Los_Angeles'
-> FROM t;
_col0
------------------------------------------------
2021-06-09 16:00:36.000000 America/Los_Angeles
(1 row)

How to convert Particular timezone of date into GMT timezone using esql of MQ?

I have the date of particular timezone, and I want to convert it to the GMT timezone, and then it needs to be inserted into DB using esql of MQ. Please help to resolve this issue.
If you want to convert a date from a format to another, you can do the following :
DECLARE inDate DATE;
DECLARE outDate DATE;
DECLARE tempDate DATE;
DECLARE patternIN CHARACTER 'yyyy-MM-dd';
DECLARE patternOUT CHARACTER 'yyMMdd';
SET tempDate = CAST(inDate AS DATE FORMAT patternIN);
-- Convert input String as Date (should match patternIN)
SET outDate = CAST(tempDate AS CHARACTER FORMAT patternOUT)
-- Convert the date object to the desired date format
Of course you need to be able to define your date pattern. I know you might need to separate the DATE from the TIME, but the object are exactly the same. A quick example of a specific cast :
CAST(CURRENT_DATE AS CHARACTER FORMAT 'yyyy-MM-dd') || 'T' || CAST(CURRENT_TIME AS CHARACTER FORMAT 'HH:mm:SS')
This will generate a date in the XML format, e.g : 2019-08-28T16:46:32

informatica datetime datatype format

I want to convert the string 20160101000000 into datetime format using expression. I have used below date function
TO_DATE(PERIOD_END_DATE),'MM/DD/YYYY HH24:MI:SS')
But my table file is not loading. My session and workflow gets succeed. My target and source is also flatfile.
I want to change the string 20160101000000 into MM/DD/YYYY HH24:MI:SS for loading data into my target table.
You need to give exact format that looks so that to_date function can understand that format and converts it into date.
TO_DATE(PERIOD_END_DATE,'YYYYMMDDHH24MISS')
So here your date looks like YYYYMMDDHH24MISS (20160101000000).
There is often confusion with the TO_DATE function... it is in fact for converting a string into a date and the function itself is to describe the pattern of the incoming date. Now if you want to convert a date field to a specified date format you must use TO_CHAR

DB2 The syntax of the string representation of a datetime value is incorrect

We have a staging table that's used to load raw data from our suppliers.
One column is used to capture a time-stamp but its data-type is varchar(265). Data's dirty: about 40% of the time, there is garbage data, otherwise time-stamp data like this
2011/11/15 20:58:48.041
I have to create a report that filters some dates/timestamps out that column but where I try to cast it, I get an error:
db2 => select cast(loadedon as timestamp) from automation
1
--------------------------
SQL0180N The syntax of the string representation of a datetime value is incorrect. SQLSTATE=22007
What do I need to do in order to parse/cast the timestamp string?
The string format for a DB2 timestamp is either:
'2002-10-20-12.00.00.000000'
or
'2002-10-20 12:00:00'
You have to get your date string in either of these formats.
Also DB2 runs on a 24 hour clock even though the output sometimes uses a 12 hour clock (AM / PM)
So '2002-10-20 14:49:50' For 2:49:50 PM
Or '2002-10-20 00:00:00' For midnight. Output would be 12:00:00 AM
It seems you have a lot of garbage data, so firt of all you should check if the data is a valid timestamp in the format you expect ('2011/11/15 20:58:48.041'). We could use a simple solution - just replace all digits with '0' and check the result format:
TRANSLATE(timestamp_column,'0','0123456789','0') = '0000/00/00 00:00:00.000'
If the format is the expected one, you should convert to DB2 timestamp. In DB2 for iSeries there is a build-in function since V6R1 TIMESTAMP_FORMAT. In your case it will look like that:
TIMESTAMP_FORMAT('2011/11/15 20:58:48.041','YYYY/MM/DD HH24:MI:SS.NNNNNN')
So the solution query combined should look something like that:
SELECT
CASE
WHEN TRANSLATE(timestamp_column,'0','0123456789','0') = '0000/00/00 00:00:00.000'
THEN TIMESTAMP_FORMAT(timestamp_column,'YYYY/MM/DD HH24:MI:SS.NNNNNN')
ELSE NULL
END
FROM
your_table_with_bad_data
EDIT
I just saw your comment that provider agreed to clean the data. You could use the solution provided to speed up the process and clean the data by yourself:
ALTER your_table_with_bad_data ADD COLUMN clean_timestamp TIMESTAMP DEFAULT NULL;
UPDATE your_table_with_bad_data
SET clean_timestamp =
CASE
WHEN TRANSLATE(timestamp_column,'0','0123456789','0') = '0000/00/00 00:00:00.000'
THEN TIMESTAMP_FORMAT(timestamp_column,'YYYY/MM/DD HH24:MI:SS.NNNNNN')
ELSE NULL
END;