{"record":{"id":"023c996dbe478c61","repo":"pentaho/pentaho-kettle","slug":"function-add-months-only-works-on-a-date","errorCode":null,"errorMessage":"Function add_months only works on a date!","messagePattern":"Function add_months 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":3388,"sourceCode":"        int day = cal.get( Calendar.DAY_OF_MONTH );\n\n        month += months;\n\n        int newyear = year + (int) Math.floor( month / 12 );\n        int newmonth = month % 12;\n\n        cal.set( newyear, newmonth, 1 );\n        int newday = cal.getActualMaximum( Calendar.DAY_OF_MONTH );\n        if ( newday < day ) {\n          cal.set( Calendar.DAY_OF_MONTH, newday );\n        } else {\n          cal.set( Calendar.DAY_OF_MONTH, day );\n        }\n\n        setValue( cal.getTime() );\n      }\n    } else {\n      throw new KettleValueException( \"Function add_months only works on a date!\" );\n    }\n    return this;\n  }\n\n  /**\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 );","sourceCodeStart":3370,"sourceCodeEnd":3406,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L3370-L3406","documentation":"Guard in the legacy Value add_months() function: the value's type is not VALUE_TYPE_DATE, so month arithmetic on a Calendar built from the value is refused. The input at fault is the current Value with a non-date type.","triggerScenarios":"Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3388 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the field passed to add_months is a Date","Convert the value to a Date before applying add_months"],"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"}