{"record":{"id":"a5812fd696db594d","repo":"pentaho/pentaho-kettle","slug":"function-add-days-only-works-on-a-date","errorCode":null,"errorMessage":"Function add_days only works on a date!","messagePattern":"Function add_days only works on a date!","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":3411,"sourceCode":"  /**\n   * Add a number of days to a Date value.\n   *\n   * @param days\n   *          The number of days to add to the current date value\n   * @return The resulting value\n   * @throws KettleValueException\n   */\n  public Value add_days( long days ) throws KettleValueException {\n    if ( getType() == VALUE_TYPE_DATE ) {\n      if ( !isNull() && getDate() != null ) {\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( getDate() );\n        cal.add( Calendar.DAY_OF_YEAR, (int) days );\n\n        setValue( cal.getTime() );\n      }\n    } else {\n      throw new KettleValueException( \"Function add_days only works on a date!\" );\n    }\n    return this;\n  }\n\n  // implement the LAST_DAY function, arguments in args[]\n  public Value last_day() throws KettleValueException {\n    if ( getType() == VALUE_TYPE_DATE ) {\n      Calendar cal = Calendar.getInstance();\n      cal.setTime( getDate() );\n      int last_day = cal.getActualMaximum( Calendar.DAY_OF_MONTH );\n      cal.set( Calendar.DAY_OF_MONTH, last_day );\n\n      setValue( cal.getTime() );\n    } else {\n      throw new KettleValueException( \"Function last_day only works on a date\" );\n    }\n\n    return this;","sourceCodeStart":3393,"sourceCodeEnd":3429,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L3393-L3429","documentation":"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.","triggerScenarios":"Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3411 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the field passed to add_days is a Date","Convert the value to a Date before applying add_days"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}