{"record":{"id":"ff793e24e53c3ff0","repo":"pentaho/pentaho-kettle","slug":"the-function-call-datediff-requires-3-arguments","errorCode":null,"errorMessage":"The function call dateDiff requires 3 arguments.","messagePattern":"The function call dateDiff requires 3 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":607,"sourceCode":"            return new Double( iDays / 7 );\n          } else if ( strType.equals( \"ss\" ) ) {\n            return new Double( ( ( endL - startL ) / 1000 ) );\n          } else if ( strType.equals( \"mi\" ) ) {\n            return new Double( ( ( endL - startL ) / 60000 ) );\n          } else if ( strType.equals( \"hh\" ) ) {\n            return new Double( ( ( endL - startL ) / 3600000 ) );\n          } else {\n            return new Double( ( ( endL - startL ) / 86400000 ) );\n          }\n          /*\n           * End Bugfix\n           */\n        }\n      } catch ( Exception e ) {\n        throw new RuntimeException( e.toString() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call dateDiff requires 3 arguments.\" );\n    }\n  }\n\n  public static Object getNextWorkingDay( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    // (Date dIn){\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        }\n        java.util.Date dIn = (java.util.Date) ArgList[0];\n        Calendar startDate = Calendar.getInstance();\n        startDate.setTime( dIn );\n        startDate.add( Calendar.DATE, 1 );\n        while ( startDate.get( Calendar.DAY_OF_WEEK ) == Calendar.SATURDAY","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L589-L625","documentation":"dateDiff requires exactly three arguments — the date-part unit string and two dates. With any other argument count it throws this RuntimeException rather than guessing which unit or dates the caller meant.","triggerScenarios":"Calling dateDiff with fewer than three arguments (e.g. omitting the unit) or more than three from script code.","commonSituations":"Forgetting the unit argument after refactoring; passing extra arguments expecting them to be ignored; confusion with language-specific dateDiff variants with different signatures.","solutions":["Call with exactly three arguments: dateDiff('d', date1, date2).","Confirm the unit string is the first argument.","Check the Script step function reference for the documented signature."],"exampleFix":"// before\nvar diff = dateDiff(date1, date2);\n// after\nvar diff = dateDiff('d', date1, date2);","handlingStrategy":"validation","validationCode":"if (unit && d1 instanceof Date && d2 instanceof Date) { var diff = dateDiff(unit, d1, d2); }","typeGuard":"function canDateDiff(u, a, b) { return typeof u === 'string' && a instanceof Date && b instanceof Date; }","tryCatchPattern":"try { var diff = dateDiff(unit, d1, d2); } catch (e) { if (/dateDiff requires 3 arguments/.test(String(e))) { diff = null; } else { throw e; } }","preventionTips":["Always supply the unit string as the first argument.","Call with exactly three arguments.","Check the signature when porting scripts between environments."],"tags":["javascript","script-step","argument-count"],"backgroundTag":"missing-required-argument","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"}