Hive provides a SQL-like interface to data stored on HDFS. Some of the rare date functions are given below (Tested on version 2.1.0).
- Get last date of month
$ hive -e 'select last_day("2017-05-01")' OK 2017-05-31 Time taken: 2.15 seconds, Fetched: 1 row(s)
- Get last day of month (Monday=1, Sunday=7)
$ hive -e 'select date_format(last_day("2017-05-01"), "u")' OK 3 Time taken: 2.46 seconds, Fetched: 1 row(s)
- Add days to a date
$ hive -e 'select date_add(last_day("2017-04-03"), 1)' OK 2017-05-01 Time taken: 2.425 seconds, Fetched: 1 row(s)
- Get first day of last month (Monday=1, Sunday=7)
$ hive -e 'select date_format(date_add(last_day("2017-04-03"), 1), "u")' OK 1 Time taken: 2.301 seconds, Fetched: 1 row(s)
P.S. Find Hive version using command: hive –version
$ hive --version Hive 2.1.0-amzn-0