hive timestamp am/pm to 24-hour timestamp
hive> select from_unixtime(unix_timestamp('20-JUN-84 11.25.32.000000021 PM','dd-MMM-yy hh.mm.ss.SSSSSSSSS aa'),'dd-MMM-yy HH.mm.ss.S') from test.dual;
hive> select from_unixtime(unix_timestamp('20-JUN-84 11.25.32.000000021 PM','dd-MMM-yy hh.mm.ss.SSSSSSSSS aa'),'dd-MMM-yy HH.mm.ss.SSSSSSSSS') from test.dual;
Related
I have an issue.
I don't find how to convert my column to the right timezone. example below :
SELECT
date AS date, --> how to convert to 'europe/paris' timezone
FROM tableName
if you have an idea.
Thanks
Use AT TIME ZONE:
select now() at time zone 'Europe/Paris';
Output:
_col0
2022-11-11 12:00:59.405 Europe/Paris
I have a dataset with timestamp strings like '2022-05-25T13:31:22.566-0400' I would like to convert it to '%Y-%m-%dT%H:%i:%s' format but adjusting for the timezone difference.
So for the above, how convert '2022-05-25T13:31:22.566-0400' to '2022-05-25T17:31:22.566' in Presto?
Thanks a lot!
You can use from_iso8601_timestamp to parse date, then cast to timestamp to remove timezone info (will be treated as UTC, at time zone 'UTC' should have the same effect) and use date_format to get required output format:
select date_format(
cast(from_iso8601_timestamp('2022-05-25T13:31:22.566-0400') as timestamp),
'%Y-%m-%dT%H:%i:%s')
Or
select date_format(
from_iso8601_timestamp('2022-05-25T13:31:22.566-0400') at time zone 'UTC',
'%Y-%m-%dT%H:%i:%s')
Output:
_col0
2022-05-25T17:31:22
This is working:
select to_char(current_timestamp AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS OF')
But when I am inserting it into a table it is failing with this error:
42804: column "load_time" is of type timestamp with time zone but expression is of type text
The to_char() function outputs a text string.
If you are trying to insert it into a TIMESTAMP WITH TIME ZONE field, then simply refer to:
current_timestamp AT TIME ZONE 'UTC'
How can I convert for example timestamp:
1559347196759
to datetime with time zone 'GMT+2' using PostgreSQL?
I believe this does what you want:
select (timestamp 'epoch' + 1559347196759 * interval '1 millisecond') at time zone '+02:00'
The first expression converts the value to UTC. The second shifts the timezone.
Convert it to a timestamp with time zone (absolute time) and convert it to the appropriate time zone:
SELECT to_timestamp(1559347196759 / 1000.0) AT TIME ZONE '-02';
timezone
-------------------------
2019-06-01 01:59:56.759
(1 row)
in my Oracle DB I have a DATE column where store date values.
All date values are in TimeZone Europe/Berlin. Now the application changes its TimeZone to UTC, this means I need to convert all existing Dates from Europe/Berlin into UTC.
Is there a way to do this natively in Oracle?
Use FROM_TZ( timestampvalue, timezone ) to convert a timestamp to a timestamp at a specific time zone and then you can use AT TIME ZONE 'UTC' to convert it to the UTC time zone and cast it back to a date:
SELECT CAST(
FROM_TZ(
CAST( your_column AS TIMESTAMP ),
'Europe/Berlin'
)
AT TIME ZONE 'UTC'
AS DATE
)
FROM your_table;