pentaho/pentaho-kettle · error · KettleValueException
TO_CHAR Couldn't convert Date to String
Error message
TO_CHAR Couldn't convert Date to String
What it means
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.
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
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3116 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/2cfb2303c112b5d5.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3116
if ( isNull() ) {
setType( VALUE_TYPE_STRING );
} else {
if ( getType() == VALUE_TYPE_DATE ) {
SimpleDateFormat df = new SimpleDateFormat();
DateFormatSymbols dfs = new DateFormatSymbols();
if ( arg1 != null ) {
dfs.setLocalPatternChars( arg1 );
}
if ( arg0 != null ) {
df.applyPattern( arg0 );
}
try {
setValue( df.format( getDate() ) );
} catch ( Exception e ) {
setType( VALUE_TYPE_STRING );
setNull();
throw new KettleValueException( "TO_CHAR Couldn't convert Date to String " + e.toString() );
}
} else {
throw new KettleValueException( "Function DAT2STR only works on a date" );
}
}
return this;
}
// implement the TO_DATE function, arguments in args[]
public Value num2dat() throws KettleValueException {
if ( isNull() ) {
setType( VALUE_TYPE_DATE );
} else {
if ( isNumeric() ) {
setValue( new Date( getInteger() ) );
setLength( -1, -1 );
} else {View on GitHub (pinned to f3058517a1)