pentaho/pentaho-kettle · error
The function call dateDiff requires 3 arguments.
Error message
The function call dateDiff requires 3 arguments.
What it means
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.
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
Example fix
// before var days = dateDiff(dateA, dateB); // after var days = dateDiff(dateA, dateB, 'd');
Defensive patterns
Strategy: validation
Validate before calling
if (arguments.length !== 3) throw new Error('dateDiff(date1, date2, unit) requires 3 arguments');
if (['y','M','d','h','m','s'].indexOf(unit) < 0) throw new Error('bad unit'); Try / catch
try { var d = dateDiff(a, b, unit); } catch (e) { // handle missing unit
throw new Error('dateDiff misuse: ' + e.message); } Prevention
- 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
When it happens
Trigger: Calling dateDiff with 2 or 4 arguments, e.g. forgetting the unit ('d') or mistakenly passing separate year/month/day fields.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- The function call dateAdd requires 3 arguments.
- The function call getNextWorkingDay requires 1 argument.
- The function call fillString requires 2 arguments.
- The function call fireToDB requires 2 arguments.
- The function call getDayNumber requires 2 arguments.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/b15457a4e132fa32.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:620
return new Double( iDays / 7 );
} else if ( strType.equals( "ss" ) ) {
return new Double( ( ( endL - startL ) / 1000 ) );
} else if ( strType.equals( "mi" ) ) {
return new Double( ( ( endL - startL ) / 60000 ) );
} else if ( strType.equals( "hh" ) ) {
return new Double( ( ( endL - startL ) / 3600000 ) );
} else {
return new Double( ( ( endL - startL ) / 86400000 ) );
}
/*
* End Bugfix
*/
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );
}
} else {
throw Context.reportRuntimeError( "The function call dateDiff requires 3 arguments." );
}
}
/**
* <p>Check if DateDiff should compensate for Local time based on the value of a Kettle property ({@link
* Const#KETTLE_DATEDIFF_DST_AWARE}).</p>
* <p>This influences calculations where the period between the given dates includes a DST change.</p>
* <p>Returning {@code true} means that the difference should be done using the dates as local time; returning {@code
* false}, means that dates should be used as UTC.</p>
*
* @return {@code true} if it is to compensate and {@code false} otherwise
* @see Const#KETTLE_DATEDIFF_DST_AWARE
*/
protected static boolean compensateForLocalTime() {
String dstAware =
Const.NVL( System.getProperty( Const.KETTLE_DATEDIFF_DST_AWARE ), Const.KETTLE_DATEDIFF_DST_AWARE_DEFAULT );
return Const.KETTLE_DATEDIFF_DST_AWARE_DEFAULT.equals( dstAware );View on GitHub (pinned to f3058517a1)