Search code examples
sqldatehiveimpala

Match date in dd-MMM-yy format to yyyy-MM-dd in Hive


I have this date 01-APR-04 but I have to do the following operation

01-APR-04 >(FROM_UNIXTIME(UNIX_TIMESTAMP(CAST(DATE_SUB(CURRENT_TIMESTAMP(),1) AS STRING),'yyyy-MM-dd'),'yyyy-MM-dd')),

How could I convert 01-APR-04 to yyyy-MM-dd format?


Solution

  • Convert '01-APR-04' to 'yyyy-MM-dd' using unix_timestamp+from_unixtime to be able to compare with date:

    select from_unixtime(unix_timestamp('01-APR-04','dd-MMM-yy'),'yyyy-MM-dd') >
           date_sub(current_date(),1) -- returns false