Please help me to convert string to timestamp.
source data is in Excel
Need to convert it as below timestamp
2019-12-15T16:35:53.663-04:00
I tried with.
select from_unixtime(unix_timestamp('12/15/2019 21:18','mm/dd/yyyy'),'YYYY-MM-DDT00:00:00-00:00')
Got below error
Both source pattern and target pattern are wrong in your query. See SimpleDateFormat for reference. Also initial string does not contain the timezone and it is not clear how are you going to derive it as -04:00. In such case it will be UTC timezone used, you can convert to other timezone using from_utc_timestamp.
Timestamp string conversion demo:
select from_unixtime(unix_timestamp('12/15/2019 21:18','MM/dd/yyyy HH:mm'),"yyyy-MM-dd'T'HH:mm:ss.SSSZ")
Result:
2019-12-15T21:18:00.000+0000
One of the column in csv file has date column. My date format is DD-Mon-YY. I getting "gdk-05058 non-numeric character found" issue. Can anyone solve this issue please. I need to import this date column
Can anyone tell please tell me how to change 2018-01-15T08:54:45.000Z to 2018-01-15 08:54:45 in PostgreSQL.
Here my timestamp: 2018-01-15T08:54:45.000Z is in text format.
I need to split it into two different columns like one for the only date:2018-01-15 and another is for only time:08:54:45
You should be able to directly cast your text to a timestamp and then cast again to date or time to get two different columns:
SELECT
('2018-01-15T08:54:45.000Z'::timestamp)::time AS time,
('2018-01-15T08:54:45.000Z'::timestamp)::date AS date
;
I have a Hive table that has the timestamps in this format 08/29/2015 0:00:08. I have tried to use the unixtimestamp functions in order to isolate the date so I can use it for comparisons, but am always getting nulls for outputs. I think I need to change the format to 2015-08-09 0:00:08 but don't know how. I am new to Hive so any guidance would be welcome.
You should use a UDF to convert them to timestamps
unix_timestamp("08/29/2015 0:00:08", "dd/MM/yyyy H:mm:ss")
Check for help here :http://docs.treasuredata.com/articles/hive-functions#date-functions
I'm very new to sql/hive. At first, I loaded a txt file into hive using:
drop table if exists Tran_data;
create table Tran_data(tran_time string,
resort string, settled double)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n';
Load data local inpath 'C:\Users\me\Documents\transaction_data.txt' into table Tran_Data;
The variable tran_time in the txt file is like this:10-APR-2014 15:01. After loading this Tran_data table, I tried to convert tran_time to a "standard" format so that I can join this table to another table using tran_time as the join key. The date format desired is 'yyyymmdd'. I searched online resources, and found this: unix_timestamp(substr(tran_time,1,11),'dd-MMM-yyyy')
So essentially, I'm doing this: unix_timestamp('10-APR-2014','dd-MMM-yyyy'). However, the output is "NULL".
So my question is: how to convert the date format to a "standard" format, and then further convert it to 'yyyymmdd' format?
from_unixtime(unix_timestamp('20150101' ,'yyyyMMdd'), 'yyyy-MM-dd')
My current Hive Version: Hive 0.12.0-cdh5.1.5
I converted datetime in first column to date in second column using the below hive date functions. Hope this helps!
select inp_dt, from_unixtime(unix_timestamp(substr(inp_dt,0,11),'dd-MMM-yyyy')) as todateformat from table;
inp_dt todateformat
12-Mar-2015 07:24:55 2015-03-12 00:00:00
unix_timestamp function will convert given string date format to unix timestamp in seconds , but not like this format dd-mm-yyyy.
You need to write your own custom udf to convert a given string date to the format that you need as present Hive do not have any predefined functions. We have to_date function to convert a timestamp to date , remaining all unix_timestamp functions won't help your problem.
select from_unixtime(unix_timestamp('01032018' ,'MMddyyyy'), 'yyyyMMdd');
input format: mmddyyyy
01032018
output after query: yyyymmdd
20180103
To help someone in the future:
The following function should work as it worked in my case
to_date(from_unixtime(UNIX_TIMESTAMP('10-APR-2014','dd-MMM-yyyy'))
unix_timestamp('2014-05-01','dd-mmm-yyyy') will work, your input string should be in this format for hive yyyy-mm-dd or yyyy-mm-dd hh:mm:ss
Where as you are trying with '01-MAY-2014' hive won't understand it as a date string