Date type conversion in hive - hive

I have a date column in String type in 'MM/dd/yyyy' format.
I have to convert this into format 'dd/MM/yyyy' format.
How to achieve this in Hive/Impala ?

you can use like this,
select from_unixtime(unix_timestamp(date ,'MM/dd/yyyy'), 'dd/MM/yyyy') from date_test;
Let me know if this works.

Since you only need to switch existing substrings you can use substring:
concat_ws('/',substr(date,1,2),substr(date,4,2),substr(date,7,4))

Related

Converting from Date format to date format in oracle

I have a date in a format like **23-APR-20** in oracle SQL and I wanna make it 23-04-2020 in date format also not string,how can I handle this please?
Please use below type conversion,
select to_date(to_char(date_column, 'DD-MON-YY'), 'DD-MM-YYYY') from table_name;
This is where you NLS_DATE_FORMAT works.
Try this:
ALTER SESSION SET NLS_DATE_FORMAT='DD-MM-YYYY';
Then all your dates will be in dd-mm-yyyy format.
Please note that oracle do not store dates in any format. It stores it in its own binary structure. NLS setting just make the format visible to your client.

How change format mask in XMLELEMENT function from Oracle DB 11g CORE 11.2.0.3.0?

I use function XMLELEMENT and XMLATTRIBUTES in my sql query, but I have problems with format date.
Example:
SELECT XMLELEMENT("triggers", XMLATTRIBUTES(3.2 AS "version"),
XMLELEMENT("request", XMLATTRIBUTES(1 AS "num"),
XMLELEMENT("lastname", trigg.last_name),
XMLELEMENT("firstname", trigg.first_name),
XMLELEMENT("middlename", trigg.middle_name),
XMLELEMENT("birthday", trigg.birth_date).....
Field XMLELEMENT("birthday", trigg.birth_date) output to console date in format:
<birthday>1980-01-05</birthday>
I need convert in format mask:
<birthday>05.01.1980</birthday>
Data about date in my datebase saved like 00.00.0000 and have type date.
I tried used function TO_DATE(date, 'DD.MM.YYYY'), TO_TIMESTAMP but this useless
Please, tell me how convert to needed format? Thanks.
You want to convert it FROM a date TO a CHAR, so use TO_CHAR
XMLELEMENT("birthday", TO_CHAR(trigg.birth_date, 'DD.MM.YYYY'))

Converting records from 'YYYY-MM-DD' format to MM/DD/YYYY in PL/SQL

I am trying to convert a specified column which is in format 'YYYY-MM-DD' and I need to convert it in MM/DD/YYYY as a data warehousing task.
The specified column is in varchar2 format.
I've been trying to use to_date, to_char but haven't succeeded yet. Any ideas?
We can try first converting your text dates into bona fide dates using TO_DATE. Then, we can use TO_CHAR to convert them to the new format.
UPDATE yourTable
SET date_col = TO_CHAR(TO_DATE(date_col, 'YYYY-MM-DD'), 'MM/DD/YYYY');
-- and maybe a WHERE clause
This being said, it is bad practice to persist your date information as text. Rather, use a proper date or timestamp column if at all possible. You would be better off creating a new date column, and then stopping after calling TO_DATE.
Inside your function/procedure, you can try this:
some_var := to_char(to_date(column_to_convert,'YYYY-MM-DD'),'MM/DD/YYYY');
It converts first the data to a date, then back to varchar2 using the desired format. Just replace the identifiers accordingly.
this will work:
select to_char(to_date('2018-10-19','YYYY-MM-DD'),'MM/DD/YYYY')from dual;

convert string to date in hive

I have this date format in hive: 20180618151752
Make the following query to leave it in the following way:
select
concat(substr(xdr.time_stop,1,8),' ',
substr(xdr.time_stop,9,2),':',
substr(xdr.time_stop,10,2),':',
substr(xdr.time_stop,11,2)) as date
from padl.fraude_vozm_xdr;
20180618 18:17:52
Now, I need to convert that string field to date, how could I do it?.
Thank you
Use from_unixtime and unix_timestamp.
from_unixtime(unix_timestamp('20180618151752','yyyyMMddHHmmss'),'yyyyMMdd HH:mm:ss')

How do I convert this oracle date

I am trying to convert from one date format to another. I am not sure how to write the functions.
My source date looks like 01/15/2009 01:23:15
The format I need is 01152009.
Thanks
Try this.
TO_CHAR(TO_DATE('01/15/2009 01:23:15','MM/DD/YYYY HH:MI:SS'),'MMDDYYY')
More info here,
http://psoug.org/reference/date_func.html
Does this work for you? It assumes the date is in date format but will work with timestamp
select to_char(YourDateField,'DDMMYYYY') from dual;
You can always convert it back to a date using the TO_DATE function if you need that format.
select TO_CHAR(TO_DATE('01/15/2009 01:23:15','MM/DD/YYYY MI:HH:SS'),'MMDDYYYY') from dual
if your field is already of data type date then you should only do:
select TO_CHAR(<fieldname>,'ddmmyyyy') ...