pentaho/pentaho-kettle · error · KettleValueException

Function add_days only works on a date!

Error message

Function add_days only works on a date!

What it means

Thrown by Value.add_days when the Value's type is not VALUE_TYPE_DATE. The method only performs Calendar-based day arithmetic on date-typed values; calling it on a String, Number, Boolean, or other Value type violates the method's type contract and aborts with KettleValueException. Fix by converting the Value to a Date (or ensuring the field is typed as Date) before adding days.

Solutions

  1. Ensure the field passed to add_days is a Date
  2. Convert the value to a Date before applying add_days
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3411 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/a5812fd696db594d. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3411

  /**
   * Add a number of days to a Date value.
   *
   * @param days
   *          The number of days to add to the current date value
   * @return The resulting value
   * @throws KettleValueException
   */
  public Value add_days( long days ) throws KettleValueException {
    if ( getType() == VALUE_TYPE_DATE ) {
      if ( !isNull() && getDate() != null ) {
        Calendar cal = Calendar.getInstance();
        cal.setTime( getDate() );
        cal.add( Calendar.DAY_OF_YEAR, (int) days );

        setValue( cal.getTime() );
      }
    } else {
      throw new KettleValueException( "Function add_days only works on a date!" );
    }
    return this;
  }

  // implement the LAST_DAY function, arguments in args[]
  public Value last_day() throws KettleValueException {
    if ( getType() == VALUE_TYPE_DATE ) {
      Calendar cal = Calendar.getInstance();
      cal.setTime( getDate() );
      int last_day = cal.getActualMaximum( Calendar.DAY_OF_MONTH );
      cal.set( Calendar.DAY_OF_MONTH, last_day );

      setValue( cal.getTime() );
    } else {
      throw new KettleValueException( "Function last_day only works on a date" );
    }

    return this;

View on GitHub (pinned to f3058517a1)