Skip to content

Date Functions in Scripts

The qie script binding exposes helpers for the current system time and for testing whether a date is within a given offset of "now". The dateUnit parameter on these helpers accepts the same set of unit names supported by the {SYSTEM_DATE} and {UTC_DATE} node tags, so the same offset semantics work whether you reach for a node tag or a JavaScript call.

Accepted dateUnit values

Long form Short code(s)
YEAR y
MONTH M
WEEK W or w
DAY d
HOUR H
MINUTE m
SECOND s
MILLISECOND S

Long forms are case-sensitive (YEAR, not year). Short codes are case-sensitive except W / w. The constants on qie.DateUnit (qie.DateUnit.DAY, etc.) resolve to the long forms.

qie.getSystemDate() and qie.getSystemDate(offset, dateUnit)

The no-arg form returns the current system date/time formatted as yyyyMMddHHmmss.SSS in the JVM default timezone:

var currentDate = qie.getSystemDate();

The two-argument overload returns the system date/time shifted by offset units of dateUnit, in the same yyyyMMddHHmmss.SSS format. A positive offset returns a future instant; a negative offset returns a past instant; zero returns the unshifted system date. The accepted dateUnit values are listed above.

var yesterday = qie.getSystemDate(-1, "DAY");
var inFiveMinutes = qie.getSystemDate(5, "m");
var lastWeek = qie.getSystemDate(-1, "W");

qie.isDateWithin(date, offset, dateUnit)

Returns true if date is inclusively within offset units of the current system time:

  • A positive offset checks the future; a negative offset checks the past. Passing 0 throws an IllegalArgumentException.
  • For DAY, WEEK, MONTH, and YEAR, the comparison snaps both date and "now" to day boundaries, start-of-day for negative offsets, end-of-day for positive. This is the long-standing behavior; any time component on date is ignored.
  • For HOUR, MINUTE, SECOND, and MILLISECOND, the comparison uses instant precision, neither side is snapped, so a date carrying an explicit time is compared at the actual instant. A date without a time component (e.g. "2026-01-15") is resolved by QIE to midnight in the JVM default timezone.
if (qie.isDateWithin(documentDate, -4, "MONTH")) {
    // documentDate is within the last 4 months (day-granularity).
}

if (qie.isDateWithin(eventTimestamp, 30, "MINUTE")) {
    // eventTimestamp is within the next 30 minutes of "now" (instant precision).
}