My question is : Is there a way to do find the last day of a month in Hive, like Oracle SQL function ? :
LAST_DAY(D_Dernier_Jour)
Thanks.
My question is : Is there a way to do find the last day of a month in Hive, like Oracle SQL function ? :
LAST_DAY(D_Dernier_Jour)
Thanks.
Something like the below could give you some inspiration. The code will give you the last day of the previous month. You can adopt it to get the last day of any month you want.
I think you can use this UDF in your Hive query to_date(string timestamp) . For example :-Returns the date part of a timestamp string: to_date("1970-01-01 00:00:00") = "1970-01-01". Now you need to write a UDF say(i.e lastDay)which will implement the following:-
Now your UDF will be something like this:-
I hope this will help your cause
You could make use of
last_day(dateString)
UDF provided by Nexr. It returns the last day of the month based on a date string with yyyy-MM-dd HH:mm:ss pattern.You need to pull it from their Github Repository and build. Their wiki page contains all the info on how to build and use it with Hive.
HTH
https://github.com/manojkumarvohra/day-extremes
You can use this project to get firstday/lastday for variety of units: day, week, month, quarter, year.
It accepts input date as String, timestamp, date in variety of valid formats and output in variety of valid formats.
Optionally you can mention an optional timestamp to be added as an interval.
Usage
FIRST_DAY_OF( unit, date, input_format[optional], output_format[optional], include_interval [optional], interval[optional])
LAST_DAY_OF( unit, date, input_format[optional], output_format[optional], include_interval [optional], interval[optional])
As of Hive 1.1.0,
last_day(string date)
function is available.last_day(string date)