Sunday 15 February 2015

hadoop - Hive: Subtracting 1 year from current date -


I want to find the best way to subtract from 1 year and get a month from the current date in a hive query . Using the following, I do not believe this leap year will be kept in mind, or if the fact is that there are different quantities in months then the code will eventually break. Any help would be greatly appreciated!

  set my_date = from_unixtime (unix_timestamp () - 365 * 60 * 60 * 24, 'yyyy-MM-dd'); Set my_date = from_unixtime (unix_timestamp () - 30 * 60 * 60 * 24, 'yyyy-MM-dd');  

Thanks!

If you have a date format like-MM-DD HH: Mm: In the SS hive, the following tasks are easy to use

concat ((year (date_field) -1), '-', (month (date_field) -1, '-', Day (date_field))

To use the IF and CASE function to apply your logic, find out whether it is a leap year or not (divided by 4 years)

< / Div>

No comments:

Post a Comment