{"record":{"id":"a06570f49854ec47","repo":"pentaho/pentaho-kettle","slug":"couldn-t-convert-string-string-to-a-timestamp-expecting","errorCode":null,"errorMessage":" : couldn't convert string [\" + string + \"] to a timestamp, expecting format [yyyy-mm-dd hh:mm:ss.ffffff]","messagePattern":" : couldn't convert string \\[\" \\+ string \\+ \"\\] to a timestamp, expecting format \\[yyyy-mm-dd hh:mm:ss\\.ffffff\\]","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaTimestamp.java","lineNumber":272,"sourceCode":"    return timestamp;\n  }\n\n  protected synchronized Timestamp convertStringToTimestamp( String string ) throws KettleValueException {\n    // See if trimming needs to be performed before conversion\n    //\n    string = Const.trimToType( string, getTrimType() );\n\n    if ( Utils.isEmpty( string ) ) {\n      return null;\n    }\n    Timestamp returnValue;\n    try {\n      returnValue = Timestamp.valueOf( string );\n    } catch ( IllegalArgumentException e ) {\n      try {\n        returnValue = (Timestamp) getDateFormat().parse( string );\n      } catch ( ParseException ex ) {\n        throw new KettleValueException( toString() + \" : couldn't convert string [\" + string\n          + \"] to a timestamp, expecting format [yyyy-mm-dd hh:mm:ss.ffffff]\", e );\n      }\n    }\n    return returnValue;\n  }\n\n  protected synchronized String convertTimestampToString( Timestamp timestamp ) throws KettleValueException {\n\n    if ( timestamp == null ) {\n      return null;\n    }\n\n    return getDateFormat().format( timestamp );\n  }\n\n  @Override\n  public Object convertDataFromString( String pol, ValueMetaInterface convertMeta, String nullIf, String ifNull,\n                                       int trimType ) throws KettleValueException {","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaTimestamp.java#L254-L290","documentation":"Thrown by ValueMetaTimestamp.convertStringToTimestamp when a string cannot be parsed into a java.sql.Timestamp. It first tries Timestamp.valueOf(), then falls back to the value metadata's configured date format; if both fail a KettleValueException is raised. The message embeds the offending string and the expected format yyyy-mm-dd hh:mm:ss.ffffff.","triggerScenarios":"Calling getTimestamp/convertData/testConvertStringToTimestamp with a String whose content does not match either 'yyyy-[m]m-[d]d hh:mm:ss[.f...]' (Timestamp.valueOf) or the configured DateFormat, e.g. '2024-01-05T10:00:00' (ISO 'T' separator) or a locale-formatted date.","commonSituations":"CSV/text inputs with alternate date formats, ISO-8601 strings from external APIs, missing fractional seconds or timezone suffixes, locale-dependent formats like '05/01/2024 10:00'.","solutions":["Normalize the string to yyyy-mm-dd hh:mm:ss[.ffffff] before passing it in","Set an explicit conversion mask (setConversionFormat / format in the field meta) matching the input so getDateFormat() can parse it","Pre-parse with a Select Values / 'String to date' step using the correct mask","Verify no stray whitespace, 'T' separators, or timezone suffixes in the source data"],"exampleFix":"// before\nrow.get(\"ts\") // \"2024-01-05T10:00:00\"\n// after\nString s = row.getString(\"ts\").replace('T', ' ');\nvalueMeta.setConversionFormat(\"yyyy-MM-dd HH:mm:ss.ffffff\");\nTimestamp ts = valueMeta.getTimestamp(s);","handlingStrategy":"validation","validationCode":"String s = value == null ? null : value.toString().trim().replace('T', ' ');\nif (s != null && !s.matches(\"\\\\d{4}-\\\\d{2}-\\\\d{2} \\\\d{2}:\\\\d{2}:\\\\d{2}(\\\\.\\\\d{1,9})?\")) {\n  throw new IllegalArgumentException(\"Timestamp string not in yyyy-mm-dd hh:mm:ss[.ffffff]: \" + s);\n}","typeGuard":null,"tryCatchPattern":"try {\n  ts = valueMetaTimestamp.getTimestamp(data);\n} catch (KettleValueException e) {\n  logError(\"Bad timestamp string: \" + e.getMessage());\n  ts = null; // or route row to error stream\n}","preventionTips":["Always set an explicit conversion format on timestamp fields read from text","Strip 'T' separators and timezone suffixes before conversion","Use testConvertStringToTimestamp in unit tests against real sample data","Keep date/time fields in Date/Timestamp objects end-to-end, not strings"],"tags":["pdi","timestamp","date-parsing","value-meta"],"backgroundTag":"invalid-date-format","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"}