I have written a query to convert epoch to date conversion in Athena but the result is not expected
select from_unixtime(cast(epoch_values as bigint))as dates from mybdbase
result is :
dates
+54113-07-13 10:11:53.000
+54113-07-13 10:11:57.000
The year is shown in the above table, How to solve this?
Use this:
from_unixtime(event_timestamp/1000000)
You could validate the results with this page:
https://www.epochconverter.com/
Related
Edited: Want to convert the format.
I am kinda new in BigQuery, recently I was working on a project. I want to convert above type of format into yyyy/mm/dd format. How will I do that?
You can combine PARSE_DATE with FORMAT_DATE to get the desired output:
SELECT FORMAT_DATE("%Y/%m/%d",PARSE_DATE("%B %d, %Y","June 10, 2014")) AS date_str
PARSE_DATE will parse the provided string into a DATE type value in BQ format (YYYY-MM-DD) and then FORMAT_DATE will format this DATE to a string with the desired output.
In case someone is wondering how to convert the whole column;
FORMAT_DATE("%Y/%m/%d",PARSE_DATE("%B %d, %Y",ColumnName)) as DesiredColumnName
I am trying hard to figure out how to convert epoch number (column name: effectivedate and datatype: string, value: 19186 ) to date format as mm/dd/yyyy and add '01/01/1970' to display the output in HIVE SQL.
For example: 19186 + 01/01/1970 should display 07/13/2022 as output
The function you are looking for is date_add(). The column effectivedate doesnt look like number of days from 1/1/1970. So using above function you can easily convert it to a full date.
SELECT date_add('1970-01-01', cast(effectivedate as BIGINT))
Test SQL SELECT date_add('1970-01-01', 19186 )
So, my table has a date field named batch that looks like this when I do
select batch from my_table;
However, i want this to be converted to the epoch representation, so that all rows contain the epoch value when I select. I tried the following query but it didn't work:
select UNIX_TIMESTAMP(batch) FROM my_table;
So, do i need to convert to datetime first? How do I get this to work?
it does work
select UNIX_TIMESTAMP('2020-01-01')
-- returns 1577833200
select UNIX_TIMESTAMP('2020-01-01 00:00:00')
-- returns 1577833200
I have a column in a bigquery table with epoch values in milliseconds. These include negative epoch values for dates before 1970 also.
How do I convert them into DATETIME format using Standard and Legacy SQL to the format:1998-10-18 13:45:55?
This should work even for dates before 1970 .i.e. negative epoch values.
I tried EXTRACT(DATETIME FROM TIMESTAMP_MILLIS(-2494865480000));
But it returns me a value with a T included in it:
1890-12-10T05:48:40
Putting aside that I don't understand your expectation on dates before 1970 you can use FORMAT_DATETIME function to format your date result as follow:
SELECT FORMAT_DATETIME("%F %T", EXTRACT(DATETIME FROM TIMESTAMP_MILLIS(-2494865480000)))
The result of this SQL is
1890-12-10 05:48:40
I have something like this:
2010-09-14 00:00:00
and would like to show only the month/year or something like this in the example above:
9/10
I was able to extract the Year part by doing this
select extract (year from E.DISCHARGE_DATE)as YR_NB
but cannot get the 9/10 result that I would like to see in my output result.
select to_char(the_date_column, 'mm/yy') from the_table;
More details in the manual: http://www.postgresql.org/docs/current/static/functions-formatting.html