Legacy Documentation
You're viewing legacy documentation for API Fortress (deployed via an on-premises container). To view documentation for the new SaaS version of API Fortress — now known as Sauce Labs API Testing and Monitoring (with Sauce Connect tunnels) — see API Testing on the Sauce Labs Cloud.

Dynamic dates

Have you ever needed to pass a future date as part of the request inside of a test? Perhaps as a check-in or check-out date? You could enter it as static value, but that means you would have to periodically update the date as time went on. Creating a dynamic date in API Fortress is a simple solution for this sort of situation. Here’s the procedure:
  1. First, open the Composer and add a Set (variable) setVar
  2. Then, enter the variable name and leave the mode as String varComp
  3. Lastly, enter the following string in the Value field:${D.format(D.plusDays(D.nowMillis(),35), ‘yyyy-MM-dd’)}
valueField Let’s analyse what this string means: D.nowMillis(): returns the current Unix epoch in milliseconds D.plusDays(): returns the provided milliseconds, plus the provided number of days (in our example, we have added 35 days to today date) D.format(): creates a timestamp with the given format, using the current timezone (in our example yyyy-MM-dd) As result, you will have something like 2018-05-15 You can obtain a past date, starting from todays date with the following string: ${D.format(D.minusDays(D.nowMillis(),35), ‘yyyy-MM-dd’)} You can also create a date based on a specified timezone: ${D.format(D.plusDays(D.nowMillis(),35), ‘yyyy-MM-dd’,’America/New_York’)} The above string create the same date as our first example using New York (EST) as the timezone. For more details about you can check our reference page