Covert Time Stamp in HIVE - hive

I have a date value (Mon Feb 29 06:01:14 CST 2016) in column. I need to convert this to the format 'YYYY-MM-DD' in hive.
Can any one please help me on this.

There is a unix_timestamp function which should help you. to_date(unix_timestamp(your_column, 'EEE MMM dd HH:mm:ss z yyyy')) This should return a string representing your date.

Related

How to insert DD MON YYYY format value into a date column in a snowflake table

My csv file has a date column having values in DD MON YYYY format eg: 28 Nov 2022.
When i tried inserting it into a date column(datatype= DATE) it is showing the below error. I have also tried using TO_DATE , TO_VARCHAR but getting the same error.
Kindly help me to resolve this.
Error: Date '28 Nov 2022' is not recognized
I want to insert the value in the same format (DD MON YYYY) into a column of date data type ,without changing the format i.e '28 Nov 2022'.
I was reading documentation (https://docs.snowflake.com/en/sql-reference/data-types-datetime.html#date) and i read: "DATE accepts dates in the most common forms (YYYY-MM-DD, DD-MON-YYYY, etc.)."
So i think the format you are trying to write is a no-supported date format.
you can:
format your date in a supported date format before write field in db.
write in a varchar datatype field, but in this case you'll lose all tools on date type.
I don't see other ways!

Convert YYY-MM-DD to MON DD, YYYY in PostgreSQL

I am having difficulty converting dates in a column from YYYY-MM-DD to Mon DD, YYYY
I think I first need to reorganize the dates and then use a case when statement to specify 01 = Jan and so on? Is that correct?
SELECT to_date(column_name, 'MM/DD/YYYY')
FROM table
gives me some incorrect dates
i.e. previous = 2012-01-29 and
result from query = 0197-06-26
Any suggestions? Thanks
I figured it out!
SELECT to_char(date(column_name), 'Mon dd, yyyy')
FROM table
gives me exactly what I need without the need of a case statement.

how can I cover [MM DD YYYY hh:mm:ss:mmm(AM/PM)] to unix timestamp?

I want to convert the following date format to "May 13 2020 12:00:00:000AM" to UNIX formatted timestamps in milliseconds. Can you please advice on doing this. Thanks in advance.

convert Date to DD-MMM-YY in redshift

I have a requirement to convert the yyyy-MM-dd date format into DD-MMM-YY.
e.g.: 2018-06-14 -> 14-JUN-18.
I tried to_char(date,'DD-MMM-YY'), however it's resulting in 14-06M-18.
Is this possible?
The format mask for the three letter month abbreviation in all caps is MON, not MMM:
to_char(date, 'DD-MON-YY')
Maybe you are coming from another API/language where MMM would have worked in that case.

TIMESTAMP in hive?

I have one column , data as 'Apr 06 2016 05:30:30' it is not in the time stamp formate, when using this one as timestamp I am getting null values. So stored as string, now I want to do some calculation on this when it is in time stamp formate. for that i converted into unixtimestamp and getting back to timestamp formate but the value of the date is changed. I used conversions as 'select from_unixtime(unix_timestamp(start_time, 'MMM DD YYYY HH:mm:ss')) from temp;'
I got value as '2015-12-27 05:30:30'.
I want final data as '2016-04-06 05:30:30'.
Please help me on this
You have just written the wrong format. The proper format string is 'MMM dd yyyy HH:mm:ss'. Take a look at https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html for reference for format strings.