I want to convert type date unix to timestamp in Informix.
My column date1 contains values as 1598915961, 1598911249, 1598911255...
expected output: 2020-02-13 15:00:00
How should I do it, please?
In Informix, you can use dbinfo() and 'utc_to_datetime':
select dbinfo('utc_to_datetime', myepoch)
The idea is that you can add the seconds to the date '1970-01-01'. I don't have Informix on-hand, but the syntax is something like this:
select datetime('1970-01-01') + interval date1 second
Related
My date column "timestamp" is currently listed as:
2020-11-16 20:27:38.033 +0000
It's formatted as timestamptz and I've tried every search on here and google to find a method to only pull the date part (in this example 2020-11-16) from the column so I can effectively start grouping data by Date.
Any help would be greatly appreciated.
Assuming (as you haven't stated) that the column is a string. This shows how to convert:
postgres=# SELECT ('2020-11-16 20:27:38.033 +0000'::timestamp)::date;
date
------------
2020-11-16
If it were already a timestamp, then just the ::date cast would work.
You can use ::DATE casting or use TO_CHAR() conversion if the aim is just to display in that format
such as
SELECT your_ts_column::DATE AS val_as_date,
TO_CHAR(your_ts_column, 'YYYY-MM-DD') AS val_as_str
FROM your_table
Demo
I would like to extract the date & hour from UTC time from the below table in bigquery. I have used timestamp for getting the date or time using the below code. I would like to apply the code for the entire column. How to apply timestamp for the entire column? Can you please assist with it?
SELECT EXTRACT(HOUR FROM TIMESTAMP "2020-05-03 16:49:47.583494")
My data is like this
I want result like this:
You can do it this way:
SELECT my_column AS original_value,
DATE_FORMAT(STR_TO_DATE(my_column, "%Y-%m-%d %H:%i:%s.%f UTC"), "%e/%m/%Y") AS date,
DATE_FORMAT(STR_TO_DATE(my_column, "%Y-%m-%d %H:%i:%s.%f UTC"), "%l%p") AS hour
FROM my_table;
I am assuming that the column is VARCHAR, that's why I am converting it to DATE.
Output:
Demo:
You can check the demo here.
Edit:
My initial thought was that OP wanted the query for MySQL (probably BigQuery is based on that). But it turns out that BigQuery is not based on MySQL. So you can use FORMAT_TIMESTAMP in BigQuery, this is how the query would look:
SELECT Occurrence AS original_value,
FORMAT_TIMESTAMP("%e/%m/%Y", Occurrence) AS date,
FORMAT_TIMESTAMP("%l%p", Occurrence) AS hour
FROM mytable
I have two different strings:
created = 2019-06-30T17:33:09.879350220Z
updated = 2019-09-25 06:42:45
I have to perform TIMESTAMP_DIFF(created_date, updated_date, HOUR) in a condition.
For the second one, CAST(updated AS TIMESTAMP) works but when I do CAST(created AS TIMESTAMP), it shows me an error Invalid Timestamp.
How can I cast the created string to a TIMESTAMP most efficiently?
Yeah, this format is kinda tricky but works with a format like this:
select parse_timestamp('%Y-%m-%dT%H:%M:%E*SZ','2019-06-30T17:33:09.879350220Z')
returns:
2019-06-30 17:33:09.879350 UTC
You can use parse_timestamp().
SELECT PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S','2019-09-25 06:42:45')
I have a date column in this format "03-FEB-16" in a database table.
I want to query the database to get UTC format equivalent of that date value:
This is the UTC format I am looking for
"2015-12-17T14:30:33Z"
Try this:
SELECT TO_CHAR(cast(SYSDATE as timestamp) at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') FROM DUAL
Change SYSDATE to say SYSDATE-150 to test different times of the year
I think I found my answer but Please feel free to post alternative ways to do it.
The following query did the trick:
select to_char(sysdate,'YYYY-MM-DD')||'T'||to_char(sysdate,'HH24:MI:SS')||'Z' from dual
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'