package com.udf;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.hadoop.hive.ql.exec.UDF;
public class MonthDiff extends UDF {
public int evaluate(String sdate,String edate ) throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date start = sdf.parse(sdate);
Date end = sdf.parse(edate);
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(start);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(sdf.parse(edate));
Calendar temp = Calendar.getInstance();
temp.setTime(sdf.parse(edate));
temp.add(Calendar.DATE, 1);
int year = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
int month = endCalendar.get(Calendar.MONTH) - startCalendar.get(C
hive自定义函数(8位日期相差月份数)
最新推荐文章于 2024-08-01 04:36:02 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)