{"record":{"id":"2cfb2303c112b5d5","repo":"pentaho/pentaho-kettle","slug":"to-char-couldn-t-convert-date-to-string","errorCode":null,"errorMessage":"TO_CHAR Couldn't convert Date to String ","messagePattern":"TO_CHAR Couldn't convert Date to String ","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":3116,"sourceCode":"    if ( isNull() ) {\n      setType( VALUE_TYPE_STRING );\n    } else {\n      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 {","sourceCodeStart":3098,"sourceCodeEnd":3134,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L3098-L3134","documentation":"Thrown when the legacy Value dat2str/TO_CHAR function's SimpleDateFormat.format() call fails while formatting the current date value (arg0 = format pattern, arg1 = DateFormatSymbols pattern chars). The value is first reset to a null String, then the underlying exception is chained into this KettleValueException — typically an invalid SimpleDateFormat pattern or an inaccessible date value.","triggerScenarios":"Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3116 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Correct the TO_CHAR date format pattern (arg0) so it is a valid SimpleDateFormat pattern","Remove or fix the DateFormatSymbols pattern characters passed as arg1","Ensure the input value actually holds a valid Date before calling TO_CHAR"],"exampleFix":null,"handlingStrategy":"try-catch","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"}