Reputation: 11
Hi I want to format date (05/07/2018 17:04:00) to (20180507) inside jmeter. Please help me.using some sampler. I need to use the date variable to make another JSON call.
Upvotes: 1
Views: 6225
Reputation: 21
The above code is not working. From the response I am getting as 17-Apr-2020 needs to change as 17/04/2020 and send to the corresponding request.
import java.text.DateFormat;
SimpleDateFormat source = new SimpleDateFormat("dd-MMM-YYYY");
SimpleDateFormat target = new SimpleDateFormat("dd/MM/YYYY");
Date date = source.parse(vars.get("C_Date"));
log.info("Date value="+date);
String newDate = target.format(date);
log.info("newDate value="+newDate);
vars.put("NewDate", newDate);][1]][1]
Upvotes: 0
Reputation: 983
Add a BeanShell Sampler with the below code in the code area:
import java.text.SimpleDateFormat;
import java.text.DateFormat;
SimpleDateFormat source = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
SimpleDateFormat target = new SimpleDateFormat("yyyyMMdd");
Date date = source.parse(vars.get("C_ticketcreatedate"));
String newDate = target.format(date);
vars.put("NewDate", newDate);
Now you can use the new date format like this ${NewDate}
Upvotes: 1
Reputation: 168197
You can do this using any suitable JSR223 Test Element and Groovy language like:
vars.put('date', Date.parse('MM/dd/yyyy HH:mm:ss', '05/07/2018 17:04:00').format('yyyyMMdd'))
After that you can access converted date as ${date}
or ${__V(date)}
where required
Upvotes: 1
Reputation: 611
You can use Jmeter __time()
function to format the date and time .
in your case use ${__time(yyyymmdd,)}
to generate the date
For More information
You can follow this Blogs for information on JMeter
Upvotes: 0