@Override
  public Object evaluate(DeferredObject[] arguments) throws HiveException {
    Date date = getDateValue(arguments, 0, converters);
    if (date == null) {
      return null;
    }
    int month = date.getMonth() - 1;
    int quarter = (month + 3) / 3;

    output.set(quarter);
    return output;
  }
GenericUDFQuarter.

Returns the quarter of the year for date, in the range 1 to 4.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFQuarter.java