protected Date lastDay(Date d) {
    date.setTimeInDays(d.toEpochDay());
    date.setDayOfMonth(date.lengthOfMonth());
    return date;
  }
GenericUDFLastDay.

Returns the last day of the month which the date belongs to.
The time part of the date will be  ignored.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLastDay.java