Convert timestamp to epoch Pentaho PDI 8 CE - pentaho

I want to convert a timestamp 2019/02/12 00:00:00.000 into Epoch time 1549486845.
I see many posts about doing the opposite conversion, but how can you convert it from timestamp to epoch?
Pentaho PDI 8 CE

I just used a Select Values step which convert the timestamp field to integer and then it is divided by 1000 in an User defined Java Expression.

Related

Converting timestamp to epoch in snowflake

I have timestamp in following format: "2022-03-08 17:11:59.901" , I want to convert them to UNIX/Epoch format up to milliseconds, somehow it only delivers till seconds part.
Is there anyway to do it?
If you have a string timestamp and you want to convert to EPOCH:
SELECT to_timestamp('2022-03-08 17:11:59.901') as ts,
date_part(EPOCH_MICROSECOND ,ts)

How can I convert an integer representing EPOCH time to a timestamp in Athena (Presto)?

I have a table where the datetime is stored as varchar but represents the EPOCH time (e.g. 1556895150). How can I get that value to be recognized as a timestamp in Athena / using Presto? something like a dateadd function would work but Athena doesn't have dateadd (I envisioned something like dateadd('second',expressoin,'1970-01-01 00:00:00'. A simple CAST(expressoin as type) does not work here because EPOCH isn't a recognized datetime data type.
You can use from_unixtime():
presto> select from_unixtime(1556895150);
_col0
-------------------------
2019-05-03 07:52:30.000
(1 row)

Getting incorrect date when converting epoch to timestamp

I have a timestamp in epoch format like this: 1551187548876. If I convert this to a timestamp using https://www.epochconverter.com/, I get the correct time back.
However, if I convert it to time using PostgreSQL to_timestamp, I get the following:
select to_timestamp(1551187548876) from my_table;
51125-03-06 14:14:36+00
Question
How can I convert epoch 1551187548876 to a timestamp in PostgreSQL?
I assume that the epoch number you have is the number of milliseconds since the epoch, not the number of seconds, as customary.
Try dividing by 1000:
select to_timestamp(1551187548.876);
to_timestamp
----------------------------
2019-02-26 14:25:48.876+01
(1 row)

Converting only time to unixtimestamp in Hive

I have a column eventtime that only stores the time of day as string. Eg:
0445AM - means 04:45 AM. I am using the below query to convert to UNIX timestamp.
select unix_timestamp(eventtime,'hhmmaa'),eventtime from data_raw limit 10;
This seems to work fine for test data. I always thought unixtimestamp is a combination of date and time while here I only have the time. My question is what date does it consider while executing the above function? The timestamps seem to be quite small.
Unix timestamp is the bigint number of seconds from Unix epoch (1970-01-01 00:00:00 UTC). The unix time stamp is a way to track time as a running total of seconds.
select unix_timestamp('0445AM','hhmmaa') as unixtimestamp
Returns
17100
And this is exactly 4hrs, 45min converted to seconds.
select 4*60*60 + 45*60
returns 17100
And to convert it back use from_unixtime function
select from_unixtime (17100,'hhmmaa')
returns:
0445AM
If you convert using format including date, you will see it assumes the date is 1970-01-01
select from_unixtime (17100,'yyyy-MM-dd hhmmaa')
returns:
1970-01-01 0445AM
See Hive functions dosc here.
Also there is very useful site about Unix timestamp

bigQuery not supporting milliseconds timestamps

I have a value in my csv file for timetamp as '1522865628160'. When I load the data in bigQuery where this field type is timestamp, it saves the timestamp as '1522865628160000'. so when I query like
select * from <tablename> limit 1
it gives me error
Cannot return an invalid timestamp value of 1522865628160000000 microseconds relative to the Unix epoch. The range of valid timestamp values is [0001-01-1 00:00:00, 9999-12-31 23:59:59.999999]; error in writing field timestamp"
please help
I think the issue here is that you tried to load your UNIX timestamp data into a timestamp column in BigQuery. A BigQuery timestamp column is not the same thing as a UNIX timestamp. The latter is just a numerical value representing the number of seconds since the start of the UNIX epoch in 1970.
So the fix here would be to load your data into an INT64 (or INTEGER if you are using legacy) column. From there, you may convert your UNIX timestamp to a bona fide date or timestamp.
There is a MSEC_TO_TIMESTAMP() function which can convert an integer number of milliseconds since the UNIX epoch to a bona fide timestamp, e.g.
SELECT MSEC_TO_TIMESTAMP(1522865628160)
2018-04-04 11:13:48 UTC