convert date format in hive

How can I convert this date :

Dec 30, 2013

in the format 'YYYY-MM-DD' in hive :


I can do explode and concat to match with given format but converting Dec to 12 is problem.


The UDF is the way to go in hive or impala, but if you have an ETL defined before loading data in HDFS, suggest let the ETL carry out the date conversion. It is important to store dates in format YYYY-MM-DD in order to leverage the TO_DATE() in hive or impala

If all your date is in this format then you can write a UDF which reads that column as string, then converts the date to a given format. Something like this:

public String convertDate(String dt2) throws ParseException{
    SimpleDateFormat incommingDateFormat = new SimpleDateFormat("MMM dd, yyyy");
    SimpleDateFormat convertedDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date dt = incommingDateFormat.parse(dt2);
    return convertedDateFormat.format(dt);

Hope this helps...!!!

Need Your Help

Why is File.Create needed to be closed?

c# .net

The following throws an exception "The process cannot access the file 'D:\MyDir\First.txt' because it is being used by another process."

Customized button text for file upload htmlcontrols

How do I change the button text of file upload HTML control from default "Browse" to anyother text?