user3871995
user3871995

Reputation: 1213

Getting date stamp to use as part of string in jmeter

I am trying to get the current date and add it as part of a string, but it is not working. This is what I have:

In User Defined Variables

currentDate    ${__time(dd/MM/yyyy)}

And then later:

CurrentDate = vars.get("currentDate");
TestFile = vars.get("testFile-" + CurrentDate + ".txt");

f = new FileOutputStream(TestFile, true);

Upvotes: 0

Views: 889

Answers (2)

Dmitri T
Dmitri T

Reputation: 168002

  1. Do you really have variable called i.e. testFile-31/03/2016.txt?
  2. Do you expect to write something into file called like above?

Actually there are some reserved characters which cannot be used in file names, i.e.

< (less than)

> (greater than)

: (colon)

" (double quote)

/ (forward slash)

\ (backslash)

| (vertical bar or pipe)

? (question mark)

* (asterisk)

I would suggest to:

  1. Reconsider your pattern

  2. Remove vars.get at all so your code would look like:

    import java.text.SimpleDateFormat;
    
    sdf = new SimpleDateFormat("dd-MM-yyyy");
    TestFile = "testFile-" + sdf.format(new Date()) + ".txt";
    f = new FileOutputStream(TestFile, true);
    

References:

Upvotes: 1

RowlandB
RowlandB

Reputation: 573

You're missing the $ in front of the {.

See

This Question

Jmeter Functions

Upvotes: 0

Related Questions