{"record":{"id":"6d8e7f78bbd730e1","repo":"pentaho/pentaho-kettle","slug":"function-last-day-only-works-on-a-date","errorCode":null,"errorMessage":"Function last_day only works on a date","messagePattern":"Function last_day 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":3426,"sourceCode":"        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;\n  }\n\n  public Value first_day() throws KettleValueException {\n    if ( getType() == VALUE_TYPE_DATE ) {\n      Calendar cal = Calendar.getInstance();\n      cal.setTime( getDate() );\n      cal.set( Calendar.DAY_OF_MONTH, 1 );\n      setValue( cal.getTime() );\n    } else {\n      throw new KettleValueException( \"Function first_day only works on a date\" );\n    }\n\n    return this;\n  }\n","sourceCodeStart":3408,"sourceCodeEnd":3444,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L3408-L3444","documentation":"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.","triggerScenarios":"Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3426 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the field passed to LAST_DAY is a Date","Convert the value to a Date before calling LAST_DAY"],"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"}