pentaho/pentaho-kettle · error · KettleValueException
Can't convert a string to a date
Error message
Can't convert a string to a date
What it means
convertValueToDate() first tries Context.jsToJava(value, Date.class); if that fails it tries to interpret the value as a string and parse it with XMLHandler.stringToDate(). When both attempts fail, it throws KettleValueException('Can't convert a string to a date'). The string form of the JS value is not in the expected date format (XML/ISO yyyy-MM-dd'T'HH:mm:ss.SSS).
Solutions
- Return a JavaScript Date object (new Date(...)) instead of a string from the script.
- Parse the string in the script with a known format before assigning it to the Date field.
- Use the step's field metadata / a Select Values or Calculator step to apply the correct date format mask matching the source string.
Example fix
// before
var orderDate = "31/12/2024"; // cannot be parsed
// after
var parts = orderDate.split("/");
var orderDate = new Date(+parts[2], +parts[1]-1, +parts[0]); // JS Date object Defensive patterns
Strategy: validation
Validate before calling
// in the script, before assigning:
var d = new Date(value); // or parse with a fixed format
if (isNaN(d.getTime())) throw new Error("Unparseable date: " + value); Type guard
function isDateLike(v) {
return v instanceof Date || !isNaN(Date.parse(String(v)));
} Try / catch
try {
Object date = JavaScriptUtils.convertFromJs(context, value, fieldName, "java.util.Date");
} catch (KettleValueException e) {
logError("Field " + fieldName + ": value is not a parseable date: " + Context.toString(value));
} Prevention
- Produce real JS Date objects for Date-typed fields instead of formatted strings.
- Agree on ISO 8601 (yyyy-MM-dd'T'HH:mm:ss.SSS) if strings must be passed.
- Convert locale-formatted dates in a dedicated parsing step before the JS step.
- Never pass epoch-millis numbers directly to Date-typed fields without conversion.
When it happens
Trigger: A BigNumber/Number/Boolean or an arbitrarily formatted string value is routed to a Date output field; the fallback string conversion yields text that XMLHandler.stringToDate cannot parse (e.g. '12/31/2024', 'yesterday').
Common situations: Locale-formatted dates from spreadsheets or CSV ('31-12-2024'); timestamps as epoch millis passed as numbers; users assuming the JS step parses arbitrary date strings.
Related errors
- No data output data type was specified for new field
- Argument of TRUNC of date has to be between 0 and 5
- Argument of TRUNC of date has to be between 0 and 5
- JavaScript conversion to BigNumber not implemented for
- Script.Log.UnexpectedeError
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/4bde7c7df2169ff1.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/core/util/JavaScriptUtils.java:222
return null;
}
} catch ( Exception e2 ) {
String string = (String) Context.jsToJava( value, String.class );
return new BigDecimal( string );
}
}
}
private static Date convertValueToDate( Object value ) throws KettleValueException {
try {
Value v = (Value) Context.jsToJava( value, Value.class );
return v.getDate();
} catch ( Exception e2 ) {
try {
String string = Context.toString( value );
return XMLHandler.stringToDate( string );
} catch ( Exception e3 ) {
throw new KettleValueException( "Can't convert a string to a date" );
}
}
}
}
View on GitHub (pinned to f3058517a1)