{"record":{"id":"69ee712dc504545d","repo":"pentaho/pentaho-kettle","slug":"function-dat2str-only-works-on-a-date","errorCode":null,"errorMessage":"Function DAT2STR only works on a date","messagePattern":"Function DAT2STR 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":3119,"sourceCode":"      if ( getType() == VALUE_TYPE_DATE ) {\n        SimpleDateFormat df = new SimpleDateFormat();\n\n        DateFormatSymbols dfs = new DateFormatSymbols();\n        if ( arg1 != null ) {\n          dfs.setLocalPatternChars( arg1 );\n        }\n        if ( arg0 != null ) {\n          df.applyPattern( arg0 );\n        }\n        try {\n          setValue( df.format( getDate() ) );\n        } catch ( Exception e ) {\n          setType( VALUE_TYPE_STRING );\n          setNull();\n          throw new KettleValueException( \"TO_CHAR Couldn't convert Date to String \" + e.toString() );\n        }\n      } else {\n        throw new KettleValueException( \"Function DAT2STR only works on a date\" );\n      }\n    }\n\n    return this;\n  }\n\n  // implement the TO_DATE function, arguments in args[]\n  public Value num2dat() throws KettleValueException {\n    if ( isNull() ) {\n      setType( VALUE_TYPE_DATE );\n    } else {\n      if ( isNumeric() ) {\n        setValue( new Date( getInteger() ) );\n        setLength( -1, -1 );\n      } else {\n        throw new KettleValueException( \"Function NUM2DAT only works on a number\" );\n      }\n    }","sourceCodeStart":3101,"sourceCodeEnd":3137,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L3101-L3137","documentation":"Guard in the legacy Value dat2str() function: the value's type is not VALUE_TYPE_DATE, so the date-to-string conversion is refused. The input at fault is the current Value whose getType() returned something other than Date.","triggerScenarios":"Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3119 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the value to a Date first (e.g. str2dat) before calling DAT2STR","Fix the upstream step so the field is produced as a Date type"],"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"}