{"record":{"id":"b15457a4e132fa32","repo":"pentaho/pentaho-kettle","slug":"the-function-call-datediff-requires-3-arguments-b15457","errorCode":null,"errorMessage":"The function call dateDiff requires 3 arguments.","messagePattern":"The function call dateDiff requires 3 arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":620,"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 Context.reportRuntimeError( e.toString() );\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call dateDiff requires 3 arguments.\" );\n    }\n  }\n\n  /**\n   * <p>Check if DateDiff should compensate for Local time based on the value of a Kettle property ({@link\n   * Const#KETTLE_DATEDIFF_DST_AWARE}).</p>\n   * <p>This influences calculations where the period between the given dates includes a DST change.</p>\n   * <p>Returning {@code true} means that the difference should be done using the dates as local time; returning {@code\n   * false}, means that dates should be used as UTC.</p>\n   *\n   * @return {@code true} if it is to compensate and {@code false} otherwise\n   * @see Const#KETTLE_DATEDIFF_DST_AWARE\n   */\n  protected static boolean compensateForLocalTime() {\n    String dstAware =\n      Const.NVL( System.getProperty( Const.KETTLE_DATEDIFF_DST_AWARE ), Const.KETTLE_DATEDIFF_DST_AWARE_DEFAULT );\n\n    return Const.KETTLE_DATEDIFF_DST_AWARE_DEFAULT.equals( dstAware );","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L602-L638","documentation":"dateDiff is a Kettle Rhino extension function that computes the difference between two dates in a given unit (y, M, d, h, m, s). It requires exactly 3 arguments: two dates and the unit string. With any other argument count it throws this RuntimeError.","triggerScenarios":"Calling dateDiff with 2 or 4 arguments, e.g. forgetting the unit ('d') or mistakenly passing separate year/month/day fields.","commonSituations":"Scripts migrated from JavaScript engines with different dateDiff signatures; the unit argument dropped during copy-paste; confusion between Kettle's dateDiff and spreadsheet-style datediff.","solutions":["Call with three arguments: dateDiff(date1, date2, 'd') where the unit is one of y, M, d, h, m, s","Ensure the unit string is present and quoted","If dates may be null, check them before calling to avoid the wrapper exception path"],"exampleFix":"// before\nvar days = dateDiff(dateA, dateB);\n// after\nvar days = dateDiff(dateA, dateB, 'd');","handlingStrategy":"validation","validationCode":"if (arguments.length !== 3) throw new Error('dateDiff(date1, date2, unit) requires 3 arguments');\nif (['y','M','d','h','m','s'].indexOf(unit) < 0) throw new Error('bad unit');","typeGuard":null,"tryCatchPattern":"try { var d = dateDiff(a, b, unit); } catch (e) { // handle missing unit\n  throw new Error('dateDiff misuse: ' + e.message); }","preventionTips":["Always pass the unit literal ('d','h', etc.) explicitly","Verify both date arguments are Date objects (d instanceof Date)","Comment the unit next to the call for readability"],"tags":["javascript","kettle","date","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"}