code: public static int datedif(EvaluationContext ctx, Object startDate, Object endDate, Object unit) {
          LocalDate _startDate = Conversions.toDate(startDate, ctx);
          LocalDate _endDate = Conversions.toDate(endDate, ctx);
          String _unit = Conversions.toString(unit, ctx).toLowerCase();
  
          if (_startDate.isAfter(_endDate)) {
              throw new RuntimeException("Start date cannot be after end date");
          }
  
          switch (_unit) {
          case "y":
              return (int) ChronoUnit.YEARS.between(_startDate, _endDate);
          case "m":
              return (int) ChronoUnit.MONTHS.between(_startDate, _endDate);
          case "d":
              return (int) ChronoUnit.DAYS.between(_startDate, _endDate);
          case "md":
              return Period.between(_startDate, _endDate).getDays();
          case "ym":
              return Period.between(_startDate, _endDate).getMonths();
          case "yd":
              return (int) ChronoUnit.DAYS.between(_startDate.withYear(_endDate.getYear()), _endDate);
          }
  
          throw new RuntimeException("Invalid unit value: " + _unit);
      }
docs: Calculates the number of days, months, or years between two dates.