How can we help?

Use dates and times

You are here:

Tests that involve dates and times or have a behavior dependent on a date can be tricky. Trudon allows you to easily create a step that will generate a date or time according to predefined properties. Such behavior can be used in action steps (ex: setting a value in an input) or expectations.

Before using dates and times in your tests, I suggest you first play with the built-in variables, as it is quite similar.

In order to integrate the date/time feature offered by Trudon, you can edit any step from the test details or the test run details using the following format:

  • {{ date 'REFERANCE_DAY' 'DATETIME_FORMAT' }}

Here are some examples:

  • {{date '5 years ago' 'MMMM Do YYYY, h:mm:ss a'}} translates to: November 10th 2015, 7:57:48 pm
  • {{date 'yesterday' 'MMM Do YY'}} translates to: Nov 10th 20
  • {{date 'today' 'dddd'}} translates to: Tuesday
  • {{date 'in 2 days' 'dddd, DD MMM'}} translates to: Friday, 13 Nov

How to format the reference day

You should pass a human-readable date phrase. Check the following examples:

  • today, now
  • yesterday, tomorrow
  • 2 years ago, in 2 years
  • 2 months ago, in 2 months
  • 2 weeks ago, in 2 weeks
  • 2 days ago, in 2 days
  • 2 hours ago, in 2 hours
  • 2 minutes ago, in 2 minutes

How to format the date/time

Trudon offers a robust way to format your date times. It takes a string of tokens and replaces them with their corresponding values. A few examples:

  • dddd, MMMM Do YYYY, h:mm:ss translates to: Sunday, February 14th 2010, 3:25:50
  • ddd, hA translates to: Sun, 3PM
  • [Today is] dddd translates to: Today is Sunday

A list of all available tokens that can be combined in any combination you might need can be checked in the table below.

TokenOutput
MonthM1 2 ... 11 12
Mo1st 2nd … 11th 12th
MM01 02 … 11 12
MMMJan Feb … Nov Dec
MMMMJanuary February … November December
QuarterQ1 2 3 4
Qo1st 2nd 3rd 4th
Day of monthD1 2 ... 30 31
Do1st 2nd ... 30th 31st
DD01 02 ... 30 31
Day of yearDDD1 2 … 364 365
DDDo1st 2nd … 364th 365th
DDDD001 002 … 364 365
Day of weekd0 1 ... 5 6
do0th 1st … 5th 6th
ddSu Mo … Fr Sa
dddSun Mon … Fri Sat
ddddSunday Monday … Friday Saturday
Week of yearW1 2 … 52 53
Wo1st 2nd … 52nd 53rd
WW01 02 … 52 53
YearYY70 71 … 29 30
YYYY1970 1971 … 2029 2030
AM/PMAAM PM
aam pm
HourH0 1 … 22 23
HH00 01 … 22 23
h1 2 … 11 12
hh01 02 … 11 12
k1 2 … 23 24
kk01 02 … 23 24
Minutem0 1 … 58 59
mm00 01 ... 58 59
Seconds0 1 … 58 59
ss00 01 ... 58 59

To escape characters in format strings, you can wrap the characters in square brackets:

  • [today is] dddd translates to: today is Friday
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Need help?
Previous Data driven testing
Next Testing private/local environments