pentaho/pentaho-kettle · error · KettleValueException

Function last_day only works on a date

Error message

Function last_day only works on a date

What it means

Guard in the legacy Value last_day() function: the value's type is not VALUE_TYPE_DATE, so the Calendar used to find the month's final day cannot be initialized. The input at fault is the current Value with a non-date type.

Solutions

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

Strategy: type-guard

When it happens

Trigger: Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3426 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/6d8e7f78bbd730e1. Report an issue: GitHub.

Appendix: source

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

        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;
  }

  public Value first_day() throws KettleValueException {
    if ( getType() == VALUE_TYPE_DATE ) {
      Calendar cal = Calendar.getInstance();
      cal.setTime( getDate() );
      cal.set( Calendar.DAY_OF_MONTH, 1 );
      setValue( cal.getTime() );
    } else {
      throw new KettleValueException( "Function first_day only works on a date" );
    }

    return this;
  }

View on GitHub (pinned to f3058517a1)