qie.isDateWithin¶
Signature: qie.isDateWithin(date, offset, dateUnit)
Returns: Boolean isWithinRange - true, if the date is inclusively within the specified offset and dateUnit; otherwise, false
Tests if a date is inclusively within a given offset of the current system time.
Note
If offset is a positive number, the date check is performed in the future. If offset is a negative number, the date check is performed in the past.
Note
An exception is thrown if offset's value is 0.
Note
For 'DAY', 'WEEK', 'MONTH', and 'YEAR' the comparison snaps both date and "now" to day boundaries; any time-of-day on date is ignored.
Note
For 'HOUR', 'MINUTE', 'SECOND', and 'MILLISECOND' the comparison uses instant precision; the time-of-day on date is honored.
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| String | date | the date to check | |
| Integer | offset | the number of dateUnits that date must inclusively be within today's date |
|
| String | dateUnit | the date unit. Valid values are 'YEAR' (or 'y'), 'MONTH' (or 'M'), 'WEEK' (or 'W' / 'w'), 'DAY' (or 'd'), 'HOUR' (or 'H'), 'MINUTE' (or 'm'), 'SECOND' (or 's'), 'MILLISECOND' (or 'S'). |
Example¶
// Generic usage
qie.isDateWithin("2026-01-01", 1, "YEAR");
var documentDate = "2026-01-01";
if (qie.isDateWithin(documentDate, -4, "MONTH")) {
// documentDate is within the last 4 months
}
var eventTimestamp = "2026-01-01 12:00:00";
if (qie.isDateWithin(eventTimestamp, 30, "MINUTE")) {
// eventTimestamp is within the next 30 minutes of now (instant precision)
}