How to convert unix/epoch timestamp into date string in Apache Phoenix SQL - sql

We have created Phoenix views on top of Hbase tables and querying the data. One of the the columns holds epoch timestamp data and we need to convert it into a valid date format, couldn't find any appropriate functions, any help much appreciated.

If type of "the column holds epoch timestamp data" is INTEGER or BIGINT, you can use:
CAST("epoch_time" AS TIMESTAMP)
if its type is VARCHAR, you should first convert value to number through TO_NUMBER()
built-in function, i.e.
CAST(TO_NUMBER("epoch_time") AS TIMESTAMP)

Related

Convert dates to UTC in DB2

I need to convert dates in a DB2 Database to UTC values.
Usually the TO_UTC_TIMESTAMP function would be the way to do this, but this method seems to only work if the source time-zone is known. The problem I'm facing is that I need an SQL script, that converts the existing dates from the current time-zone of the database to UTC, without hard-coding the current time-zone.
What I already tried is the following SQL:
-- assuming there is a table called 'test' with a column 'col1' of the type timestamp
SELECT col1 AS my_time_zone, TO_UTC_TIMESTAMP(col1, CURRENT TIMEZONE) AS utc FROM test;
This does not convert the date value, because CURRENT TIMEZONE returns an integer value (in my case 10000 for UTC+01:00). This integer value seems to be converted to a VARCHAR, that cannot be interpreted by the TO_UTC_TIMESTAMP function.
From the DB2 documentation:
timezone-expression
[...] If the expression is not a VARCHAR, it is cast to VARCHAR before the function is evaluated.
[...] If the timezone-expression returns a value that is not a time zone in the IANA time zone database, then the value of expression is returned without being adjusted.
So my question is: Is there a way to get the current time-zone from a DB2 database, in a format that the TO_UTC_TIMESTAMP function can use? Or is there any other way to convert dates from the current time-zone to UTC?
That would be simply col1 - current timezone, given that col1 has the timestamp data type.

postgresql - creae view showing showing time as human readable [duplicate]

I am new to postgresql bot not to sql in general. I have a table that I need to read values from, on of the columns is a unix timestamp that I want to convert in to a more human readable format thus I found this:
SELECT lt,dw,up,to_char(uxts, 'YYYY-MM-DD HH24:MI:SS')
from products;
But that produces an error:
ERROR: multiple decimal points
I am lost here. I am sure someone can show me how to do it. The documentation isn't that clear to me. Postgresql 9.5 is the database.
to_char() converts a number, date or timestamp to a string, not the other way round.
You want to_timestamp()
Convert Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp
So just apply that function on your column
SELECT lt,dw,up,to_timestamp(uxts) as uxts
from products;
This assumes that uxts is some kind of number data type (integer, bigint or double precision)

Converting timestamp on whole table in bigquery

I have this table which stores millions of rows of data. This data has a date that indicates when was the data entered. I store the data in NUMERIC schemas with EPOCH UNIX as the format. However, I wanted to convert them to human date (yyyy-mm-dd hh:mm:ss) and later sort them by date not queried date.
However, it took me so long to find a suitable way. Here's my attempt.
I used SELECT CAST(DATE(timestamp) AS DATE) AS CURR_DT FROM dataset.table but it gave me this error:
No matching signature for function DATE for argument types: NUMERIC. Supported signatures: DATE(TIMESTAMP, [STRING]); DATE(DATETIME); DATE(INT64, INT64, INT64) at [1:13]
I used this method BigQuery: convert epoch to TIMESTAMP but still didn't fully understand
I'm a novice in coding so I hope you guys understand the situation. Thanks!
If I am understanding your question correctly you would like to take a numeric EPOCH time that is stored as an integer and convert it to a timestamp?
If so you can use the following in BigQuery Standard SQL:
select TIMESTAMP_SECONDS(1606048220)
It gives the output of:
2020-11-22 12:30:20 UTC
Documentation
If you only want the date component, then you would convert to a date after converting to a timestamp. Presumably you have seconds, so you would use TIMESTAMP_SECONDS() -- but there are similar functions for milliseconds and microseconds.
For just the date:
select date(timestamp_seconds(col))
Note that this removes the time component.

How to merge two columns of different temporal datatypes in DolphinDB?

The datatype of the column date is DATE and the datatype of the column time is TIMe. I want to merge the two column and generate a new column whose datatype is TIMESTAMP. Which function should I use? enter image description here
timestamp(dateCol) + int(timeCol)
First convert the date column to timestamp type and then add the milliseconds within the day. DolphinDB represents the time object by milliseconds internally. So we directly convert the time column to integer.

Convert Timestamp to DateTime in SQL (Google Big Query)

I'm trying to figure out how to convert a timestamp into a datetime object in SQL (I'm using Google Big Query).
Here's what the timestamp column looks like — each row contains a 10 digit integer.
Any help would be appreciated!
You want timestamp_seconds():
select timestamp_seconds(time_stamp) as utc_timestamp
Your column looks like a Unix timestamp, which is the number of seconds since 1970-01-01.