Apache JMeter – timeShift Function

timeShift is an in-build function of Apache JMeter and its type is ‘Information’, which returns the past or future date and time in various formats like epoch or human-readable time etc. By the way, JMeter in-build functions are divided into eight categories which are:

  1. Information
  2. Input
  3. Calculation
  4. Formatting
  5. Scripting
  6. Properties
  7. Variables
  8. Strings
Apache JMeter - timeShift Function

Syntax: ${__timeShift}

Type: Information

Purpose: To generate the past or future date and time in the required format.

Input Argument: The timeShift function has 5 arguments among them 2 are optional:

  • Time Format: Refer to the above table (Table 01) and use the argument to create the time format string. e.g. yy-MM-dd
  • Date to Shift: By default, it uses the current timestamp. In case you want to shift the date/time from a particular date/time then specify it. e.g. 2020-10-20
  • How much shift: Specify the amount of day/time to shift
    • P denotes Parse for a future date
    • -P denotes Parse for a past date
    • PT denotes Parse for a future time
    • -PT denotes Parse for a past time
    • D denotes Day
    • H denotes Hour
    • M denotes Minute
    • S denotes Second
  • String Format (Optional)
  • Name of variable (Optional)

Example: If someone wants to get the 2 days prior date on 17/03/2024 then he can use ${__timeShift(dd/MM/yyyy,,-P2D,,)}. Similarly:

${__timeShift(yyyy-MM-dd HH:mm:ss,,P2D,,)} will generate a future date by adding 2 days in the current day.

${__timeShift(yyyy-MM-dd HH:mm:ss,,PT2H,,)} will generate a future time by adding 2 hours in the current time.

${__timeShift(yyyy-MM-dd HH:mm:ss,,PT2M,,)} will generate a future time by adding 2 minutes in the current time.

${__timeShift(yyyy-MM-dd HH:mm:ss,,P2DT2H,,)} will generate a future date and time by adding 2 days and 2 hours in the current timestamp.

${__timeShift(yyyy-MM-dd HH:mm:ss,,-PT2M,,)} will generate a past time by reducing 2 minutes in the current time.

${__timeShift(yyyy-MM-dd HH:mm:ss,,-P2DT2H,,)} will generate a past date and time by reducing 2 days and 2 hours in the current timestamp.

${__timeShift(yyyy-MM-dd HH:mm:ss,2020-10-20,P2D,,)} will generate 2020-10-22 which is the next 2nd day from the specified date.

Return Value: This function returns the number, text and symbol which are used for the date/time format. If a variable name is provided as an argument then the return value is stored in that variable.

Example: If you use ${__timeShift(dd/MM/yyyy,,-P2D,,cTimeShift)} to capture the current timestamp then variable cTimeShift will store the generated value and you can use ${cTime} wherever you want to pass the generated value.

Related Functions:


You may be interested:


Leave a Comment