I would like to convert a UNIX figure in to a GMT timestamp.
I first convert the UNIX number to UTC, but cannot seem to convert it to GMT?
For Example
Date
UNIX
Event_Unix_Timestamp
Country
2022-03-10
1646899782
2022-03-10 08:09:42 UTC
Nigeria
The query I currently have is :
SELECT
DATE
, EVENTUNIX
, TIMESTAMP_SECONDS (EventUNIX) AS Event_Unix_Timestamp
, COUNTRY
FROM TABLE
GROUP BY 1,2,3
I have tried the below function:
TIMESTAMP (DATETIME(TIMESTAMP_SECONDS(EventUNIX) , "Europe/London") ) AS Video_Event_Unix_Timestamp
and with 'GMT'
But this doesn't work.
Any help would be great! Thanks!
Related
I am using Oracle SQL. I want to convert three columns to datetime in sql.
My data looks like:
DAY (DATE) HOUR (NUMBER) HALFHOUR (NUMBER)
21.04.22 11 22
21.04.22 11 23
21.04.22 12 24
21.04.22 12 25
21.04.22 13 26
21.04.22 13 27
....
I need to combine each row to the following specific format, in one column:
2022-04-21T13:30:00.00Z
Moreover, it should be converted from an utc time where data comes from (like UTC+3) to UTC+0 automatically.
How do I do this? I googled a lot, but cant do it.
Thanks :)
The solution to your problem is:
SELECT T1.*,
TO_CHAR(FROM_TZ(TO_TIMESTAMP(DAY||' '||HOUR||':'||HALFHOUR, 'DD.MM.RR HH24:MI'), 'Europe/Berlin') AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.ff2"Z"') as time_utc
FROM T1;
TO_TIMESTAMP:
TO_TIMESTAMP converts char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2
datatype to a value of TIMESTAMP datatype.
Syntax is:
TO_TIMESTAMP( string1 [, format_mask] ['nlsparam'] )
FROM_TZ:
In Oracle Database, the FROM_TZ() function converts a timestamp value
and a time zone to a TIMESTAMP WITH TIME ZONE value. Pass the
timestamp value and the time zone as two separate arguments, and the
function returns them as a TIMESTAMP WITH TIME ZONE value.
Syntax is :
FROM_TZ(timestamp_value, time_zone_value)
time_zone_value all possible values an be found out using the below query:
SELECT * FROM V$TIMEZONE_NAMES;
The output generated using above two functions is the time in the germany time-zone and is converted to UTC time zone using the " AT TIME ZONE 'UTC' "
Then using TO_CHAR it is converted to the required format.
You can see the working sample example at the below link:
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=b030170a2c5536b4f80f1287bbfe4aca
I've been trying to convert each UTC time back to the appropriate local timezone using standard SQL in GBQ, but couldn't find a good way to do it dynamically because I might have tons of different timezone name within the database. I'm wondering if anyone has an idea?
The table I have contains 2 different columns (see screenshot)
Below example is for BigQuery Standard SQL
#standardSQL
WITH `project.dataset.yourtable` AS (
SELECT 'Pacific/Honolulu' timezone, TIMESTAMP '2020-03-01 03:41:27 UTC' UTC_timestamp UNION ALL
SELECT 'America/Los_Angeles', '2020-03-01 03:41:27 UTC'
)
SELECT *,
DATETIME(UTC_timestamp, timezone) AS local_time
FROM `project.dataset.yourtable`
with output
Row timezone UTC_timestamp local_time
1 Pacific/Honolulu 2020-03-01 03:41:27 UTC 2020-02-29T17:41:27
2 America/Los_Angeles 2020-03-01 03:41:27 UTC 2020-02-29T19:41:27
Need to get the date part from column Start_DateTime (varchar data type) which is having data like '06/04/19 10:44 AM CDT' , '06/10/19 11:56 AM EDT' and need to convert the time zone to CST time zone
I have a user defined function dbo.fn_UTCtoCST that will convert the time zone but am trying to combine all this in a select query to get the desired result
SELECT
Start_DateTime
,Inspector
,Status
,Distance
,Location
from XYZ
If your function is scalar value function(returning one value) then this might will work for you.
select *
from A
cross apply dbo.fn_UTCtoCST(date) cstdate.
i need convert a date field in UTC to GMT-5, this is my query;
Select
A1.NAME23,
TO_CHAR(A1.TIME_END,'YYYY/MM/DD HH24:MI:SS')TIME_END,
A1.VAR43
From table
i trying this
select to_char(cast(A1.TIME_END at time zone 'GMT-5' as date ),'YYYY/MM/DD HH24:MI:SS') as GMT-5 from table
but dont work
any suggestions
thanks.
If the column is a DATE datatype, then it's simply:
select time_end - 5/24 from table
It must be this one:
A1.TIME_END at time zone '-05:00'
I use postgres for the rails app and I have a unix timestamp in postgresql db. I have a requirement to select and group by the dd-mm-yyyy and by month name.
Consider I have the following unix timestamp
1425148200
and I would need to change this to datetime and I used to_timestamp which returned
2015-02-28 18:30:00 UTC
and I tried to convert the datetime to local timezone using
::timestamp without time zone AT TIME ZONE 'IST'
but that did not give time in required timezone and instead it returned
2015-02-28 16:30:00 UTC
and I tried to get the date part using ::date which returned
Sat, 28 Feb 2015
So please help me get the dd-mm-yyyy in specified timezone and month name(March) from the unix timestamp.
Thanks in Advance!
select to_char(to_timestamp('1425148200')::timestamptz at time zone 'UTC-5:30','DD-MM-YYYY & of course Month')
01-03-2015 & of course March
It is postgres mistake I guess
according to http://www.postgresql.org/docs/7.2/static/timezones.html