How to use Future or Past Date in Jmeter Without any Code: Jmeter is one of the most popular open-source load testing tools. Jmeter itself has some of the built-in functions which we need regularly while creating scripting. one of the useful function is __timeshift which will be used for get future date in jmeter or past date in Jmeter
- timeshift
- Base encoding
- Generating time in different formats
- Url encode
- Url decode
- Random String
- Random Number
- UUID
- Random Date
- File to string
- CSV Reader
In some scenarios, we need to use the future date to complete the flow. For instance, when user trying to book a flight or placing food order user need to choose future time whether it may be in minutes or an hour or even days
In JMeter, we have a function name __timeShift which will allow us to create a future date in any format.
Go To Function Helper Dialogue option is changed in the latest version of JMeter
Then select __timeShift function like below
In the First row, we need to mention which Format we need like below.
DD-MM-YYYY HH:MM:SS
For more Patterns info
Letter for Pattern | Date or Time component | Examples |
G | Era designator | AD |
y | Year | 2019(yyyy),19(yy) |
M | Month in year | July(MMMM), Jul(MMM), 07(MM) |
w | Results in the week in year | 30 |
W | Results in the week in a month | 2 |
D | Gives the day count in the year | 266 |
d | Day of the month | 09(dd), 9(d) |
F | Day of the week in the month | 4 |
E | Day name in the week | Monday, Mon |
u | Day number of a week where 1 represents Monday, 2 represents Tuesday and so on | 2 |
a | AM or PM marker | AM |
H | Hour in the day (0-23) | 12 |
k | Hour in the day (1-24) | 23 |
K | Hour in am/pm for 12 hour format (0-11) | 0 |
h | Hour in am/pm for 12 hour format (1-12) | 12 |
m | Minute in the hour | 16 |
s | Second in the minute | 20 |
S | Millisecond in the minute | 560 |
z | Timezone | Indian Standard Time; IST; GMT-05:30 |
Z | Timezone offset in hours (RFC pattern) | -0800 |
X | Timezone offset in ISO format | -08; -0800; -08:00 |
In the second row from which date you want to change by default, it will be current timestamp if we need we can give another time
In the third row need to time-shift duration whether it can be in minutes, seconds, hours, days,
for example if i need now + 2 days date then below will be the output
after adding 2 days future date output will be like this
Examples :
- PT15M parses as 15 minutes( adds 15 Minutes for the given time in the second row )
- PT10H parses as 10 hours(Adds 10 Hours for a given time)
- P2D parses as 2 days(adds 2 days for the given date in the Second row)
- -P6H3M parses as -6 hours and -3 minutes(subtracts 6 hours 3 minutes from a given date in the second row )
H: H stands for hours
M: M Stands for Minutes
S: S Stands for Seconds
D: D Stands for Days
P: P stands for Adding
-P: Stands for Subtracting
In the fourth row, we can save the create Date into a variable.
Also Read: How to Record HTTP Application in Jmeter