{"record":{"id":"54d1c78727f578b6","repo":"pentaho/pentaho-kettle","slug":"function-dat2num-works-only-on-dates","errorCode":null,"errorMessage":"Function DAT2NUM works only on dates","messagePattern":"Function DAT2NUM works only on dates","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":3262,"sourceCode":"    }\n    return this;\n  }\n\n  public Value dat2num() throws KettleValueException {\n    if ( isNull() ) {\n      setType( VALUE_TYPE_INTEGER );\n      return this;\n    }\n\n    if ( getType() == VALUE_TYPE_DATE ) {\n      if ( getString() == null ) {\n        setNull();\n        setValue( 0L );\n      } else {\n        setValue( getInteger() );\n      }\n    } else {\n      throw new KettleValueException( \"Function DAT2NUM works only on dates\" );\n    }\n    return this;\n  }\n\n  /**\n   * Performs a right and left trim of spaces in the string. If the value is not a string a conversion to String is\n   * performed first.\n   *\n   * @return The trimmed string value.\n   */\n  public Value trim() {\n    if ( isNull() ) {\n      setType( VALUE_TYPE_STRING );\n      return this;\n    }\n\n    String str = Const.trim( getString() );\n    setValue( str );","sourceCodeStart":3244,"sourceCodeEnd":3280,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L3244-L3280","documentation":"Guard in the legacy Value dat2num() function: the value's type is not VALUE_TYPE_DATE, so the date-to-number (epoch) conversion is refused. The input at fault is the current Value with a non-date type.","triggerScenarios":"Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3262 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the field passed to DAT2NUM is a Date","Convert the value to a Date first (e.g. str2dat or num2dat) before calling DAT2NUM"],"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"}