Dealing with Dates and Times

Dealing with Dates and Times

Dates and times change constantly, but your automated tests should continue to work regardless of when they run. For example, a test that selects tomorrow’s delivery date must select a different date each day.

testRigor makes this possible with predefined variables, natural-language date commands, and formatting options. You can use these features to enter, save, and validate dates without hardcoding values or writing JavaScript.

For the examples in this lesson, assume today is October 13, 2026, and the current time is 9:05 AM. This gives us a consistent reference point for understanding the results. Actual values will depend on when the test runs and the test suite’s configured time zone.

Using Predefined Date and Time Variables

Predefined variables are values that testRigor automatically provides during test execution. They allow you to use the current date or time without manually calculating or entering it.

For example, instead of entering a fixed year such as 2026, you can use the variable todayYear. The test will then use the current year whenever it runs.

enter stored value "todayYear" into "Year"

Expected result: If the test runs on October 13, 2026, the value entered is 2026. When the same test runs in 2027, the value automatically changes to 2027.

Predefined date and time variables are organized below by the type of value they return.

Year Variables

These variables provide the current year in four-digit or two-digit format.

  • todayYear — 2026
  • todayYearShort — 26
  • nextYear — 2027
  • previousYear — 2025
  • nextYearShort — 27
  • previousYearShort — 25

Month Variables

Month variables are available as full names, abbreviated names, or numbers. Numeric months can also include a leading zero when needed.

  • todayMonth — October
  • todayMonthShort — Oct
  • todayMonthNumber — 10
  • todayMonthNumberTwoDigits — 10
  • nextMonth — November
  • previousMonth — September
  • nextMonthShort — Nov
  • previousMonthShort — Sep
  • nextMonthNumber — 11
  • previousMonthNumber — 9
  • nextMonthNumberTwoDigits — 11
  • previousMonthNumberTwoDigits — 09

Note: Two-digit month variables add a leading zero to single-digit months. For example, September is represented as 09 instead of 9.

Day Variables

These variables provide the day of the month or the day of the week.

  • todayDayOfMonth — 13
  • todayDayOfMonthTwoDigits — 13
  • nextDayOfMonth — 14
  • previousDayOfMonth — 12
  • nextDayOfMonthTwoDigits — 14
  • previousDayOfMonthTwoDigits — 12
  • todayDayOfWeek — Tuesday
  • todayDayOfWeekShort — Tue
  • nextDayOfWeek — Wednesday
  • previousDayOfWeek — Monday

On dates with a single-digit day, todayDayOfMonthTwoDigits includes a leading zero. For example, on October 5, it returns 05.

Time Variables

Time variables provide the current hour, minute, second, or AM/PM indicator. The following examples assume the time is 9:05:07 AM.

  • nowHour — 9
  • nowHourTwoDigits — 09
  • nowHourAmPm — 9
  • nowHourTwoDigitsAmPm — 09
  • nowAmPm — AM
  • nowMinute — 5
  • nowMinuteTwoDigits — 05
  • nowSecond — 7
  • nowSecondTwoDigits — 07

Additional next and previous variations are available for hours, minutes, and seconds.

Complete Date and Time Variables

When you need more than one date or time component, testRigor provides variables containing complete values.

  • nowDateIso — 2026-10-13
  • nowTimeIso — 09:05:07
  • nowDateTimeIso — date and time in ISO-style format with time-zone information
  • nowMillisecondsFrom1970 — current timestamp in milliseconds
  • nowUnixTime — current Unix timestamp in seconds
  • nowDateTimeRFC1123UTC — date and time in RFC 1123 UTC format
  • nowNanosecond — nanosecond component of the current time

For example, to save the current date in ISO format:

save stored value "nowDateIso" as "currentDate"

Expected result: The variable currentDate contains 2026-10-13.

You can find the complete list of available variables in the Date and Time Variables documentation.

Important: These variables use the time zone configured in the test suite. Check the suite’s time-zone setting if the date or time differs from what you expect.

Building a Date from Variables

Sometimes an application requires a date in a format that is not directly available as a predefined variable. Instead of entering each part separately, you can combine multiple variables into one formatted value.

Use the string with parameters command to combine the month, day, and year.

save string with parameters "${todayMonth} ${todayDayOfMonth}, ${todayYear}" as "todayFullDate"

Here’s what happens when the test runs on October 13, 2026:

  • ${todayMonth} becomes October.
  • ${todayDayOfMonth} becomes 13.
  • ${todayYear} becomes 2026.

Expected result: The variable todayFullDate contains October 13, 2026.

You can then use this saved value in another step:

check that page contains stored value "todayFullDate"

This validates that the complete current date appears on the page.

Tip: Use todayDayOfMonthTwoDigits instead of todayDayOfMonth when the date format requires days such as 05 instead of 5.

Working with Past and Future Dates

Many automated tests need dates that are different from the current date. A booking form might require a reservation three days from now, while a reporting application might need to validate yesterday’s data.

Predefined variables give you the current date or an adjacent value. For more flexible calculations, testRigor supports natural-language expressions such as:

  • tomorrow
  • yesterday
  • next week
  • next month
  • next year
  • in 2 days
  • in 3 hours
  • in 5 minutes
  • in 30 seconds

These expressions allow you to calculate dates and times without JavaScript.

For example, to enter tomorrow’s date into a delivery date field:

enter us date "tomorrow" into "Delivery Date"

Expected result: 10/14/2026.

To enter the date two days from now:

enter us date "in 2 days" into "Appointment Date"

Expected result: 10/15/2026.

To enter the year that follows the current year:

enter year "next year" into "Year"

Expected result: 2027.

Remember: The dates above are based on the reference date of October 13, 2026. The actual results change automatically depending on the execution date.

Choosing the Correct Date and Time Format

Different applications require different date and time formats. Some fields expect a complete date, while others require only a month, day, year, or time component.

testRigor lets you specify the format directly in the command.

Date Formats

The following examples use October 13, 2026 as the current date.

  • us date — complete US date, such as 10/14/2026.
  • us date short — US date with two-digit year, such as 10/14/26.
  • year — four-digit year, such as 2027.
  • year short — two-digit year, such as 27.
  • day of the month — numeric day, such as 14.
  • day of the week — full weekday name, such as Wednesday.
  • day of the week short — abbreviated weekday name, such as Wed.
  • month number — numeric month, such as 11.
  • month name — full month name, such as November.
  • month name short — abbreviated month name, such as Nov.

For example:

enter us date short "tomorrow" into "Date"
enter day of the week short "tomorrow" into "Weekday"
enter month name "next month" into "Month"

Expected results: The commands enter 10/14/26, Wed, and November, respectively.

Time Formats

Time commands work similarly. You can enter an entire time or only the components required by the application.

  • hours — hour in 24-hour format.
  • hour am pm — hour in 12-hour format.
  • minutes — minute component.
  • seconds — second component.
  • hours and minutes — time in hour:minute format.
  • hours minutes and seconds — time including seconds.
  • am pm — AM or PM indicator.

For example, suppose the current time is 9:05 AM and you want to enter the time three hours from now:

enter hours and minutes "in 3 hours" into "Start Time"

Expected result: 12:05.

You can also enter the hour and AM/PM indicator separately:

enter hour am pm "in 3 hours" into "Hour"
enter am pm "in 3 hours" into "AM/PM"

Expected results: 12 and PM.

See the Date/Time Format Commands documentation for the full list.

Using Leading Zeros

Some applications require date and time values to contain two digits, even when the number is less than ten.

For example, a date picker might expect 05 instead of 5, or 03 instead of 3.

Add with leading zeros after the date or time component to request this format.

enter day of the month with leading zeros "tomorrow" into "Day"

Expected result: If the current date is October 4, 2026, the value entered is 05.

Other examples include:

enter month number with leading zeros "next month" into "Month"
enter minutes with leading zeros "in 5 minutes" into "Minutes"
enter seconds with leading zeros "in 30 seconds" into "Seconds"

The output depends on the resulting date or time. Whenever the result is a single-digit number, a zero is added to the beginning.

See the Leading Zeros documentation.

Saving and Reusing Dates

Sometimes you need to use the same dynamic date in several steps. Instead of calculating it repeatedly, you can save it as a variable.

Use the save command instead of enter, followed by as and a variable name.

save US date "tomorrow" as "Delivery Date"

Expected result: If the test runs on October 13, 2026, the saved variable contains 10/14/2026.

You can then use the saved value in other steps:

enter stored value "Delivery Date" into "Requested Delivery"
check that page contains stored value "Delivery Date"

The first step enters the saved date into a field. The second checks that the saved date appears on the page.

You can also save individual date and time components:

save day of the month "tomorrow" as "Day Value"
save month number "next month" as "Month Value"
save minutes "in 5 minutes" as "Minutes Value"

See the Saving Date/Time into a Variable documentation.

Calendars and Date Pickers

Not every application allows dates to be typed directly. Some use calendars, dropdowns, or date picker wheels.

In these cases, you may need to interact with the individual elements instead of entering a complete formatted date.

Selecting a Date on a Calendar

Suppose the calendar is already displaying October 2026 and you want to select October 13.

You can use the predefined day variable to click the correct date:

click stored value "todayDayOfMonth" in the context of "October 2026"

Expected result: The test clicks day 13 within the October 2026 calendar.

This example assumes the calendar is already showing the correct month and that the calendar’s visible structure allows the month to be used as context.

If a calendar displays another month, navigate to the desired month before selecting the day. The exact navigation commands depend on how the application implements its calendar.

Selecting a Date on a Date Picker

For date pickers that allow individual month, day, and year values, you can enter each component separately.

enter stored value "todayMonth" into "month"
enter stored value "todayDayOfMonth" into "day"
enter stored value "todayYear" into "year"

Expected result: The picker receives October, 13, and 2026.

Note: Use the interaction method that matches your application. Some date pickers accept text, while others require clicks, selections, or swipes.

Advanced: Date Calculations with JavaScript

For most everyday date and time calculations, the natural-language commands covered earlier are simpler and easier to maintain.

However, some test cases require more specialized calculations. In those situations, testRigor also supports JavaScript expressions compatible with ECMAScript 5.1.

You do not need to know JavaScript to complete the standard examples in this lesson. The following example simply demonstrates an additional option.

Example: Get the Day of the Month Seven Days from Now

Suppose the current date is October 13, 2026, and you need to save the numerical day of the month seven days later.

save expression "var d = new Date(); d.setDate(d.getDate()+7); ''+d.getDate();" as "dayInSevenDays"

This expression performs three actions:

  1. new Date() gets the current date.
  2. d.setDate(d.getDate()+7) moves the date forward seven days.
  3. d.getDate() returns the resulting day of the month.

Expected result: The variable dayInSevenDays contains 20, because seven days after October 13 is October 20.

Changing +7 to -7 would instead move the date seven days into the past.

Important: JavaScript date calculations may use the execution environment’s date and time settings. For standard date operations, prefer testRigor’s built-in date commands and predefined variables.

Choosing the Right Approach

There are several ways to work with dates in testRigor. Choose the simplest method that meets your needs.

  • Predefined variables: Use these when you need the current year, month, day, time, or an adjacent value.
  • Natural-language date commands: Use these for dates such as tomorrow, next week, or several days in the future.
  • String with parameters: Use this when you need to combine individual values into a custom format.
  • Saved date variables: Use these when the same calculated value is needed in multiple steps.
  • JavaScript expressions: Use these for specialized calculations that require additional flexibility.

Whenever possible, prefer the built-in date and time commands. They make tests easier to read, understand, and maintain.

Test your knowledge

enter year "tomorrow" into "Delivery Date"

enter us date "tomorrow" into "Delivery Date"

enter month name "tomorrow" into "Delivery Date"

enter us date short "tomorrow" into "Delivery Date"

save day of the week "tomorrow" as "Tomorrow Day"

save month number "tomorrow" as "Tomorrow Day"

save day of the month with leading zeros "tomorrow" as "Tomorrow Day"

save year short "tomorrow" as "Tomorrow Day"