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

Time:01-29

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?

CodePudding user response:

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
  •  Tags:  
  • Related