I have extracted an element using Expath extractor and it is returning below: Nov. 2015 However I only need the date that is 11/1/2015.

  • can you share the test plan configuration and the result you are getting? – Milin Patel Oct 11 at 4:44

Assuming you have this Nov. 2015 stored as a JMeter Variable called oldDate you can do something like:

vars.put('newDate', Date.parse('MMM. yyyy', vars.get('oldDate')).format('MM/d/yyyy'))

If everything goes well you will be able to refer the converted date as ${newDate} where required

Demo:

JMeter GRoovy convert date

See Creating and Testing Dates in JMeter - Learn How for more tips and tricks with regards to working with dates in JMeter

  • I didn't get succeded. Code: vars.put('newDate', Date.parse('MMM. yyyy', vars.get('${testxp1}')).format('MM/d/yyyy')) and error is 2018-10-12 17:39:51,157 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException. I appreciate your help – Nitish Oct 12 at 12:19
  • 1. Make sure that your ${testxp1} variable exists and has value of Nov. 2015 using Debug Sampler and View Results Tree listener combination. 2. Amend your code to look like: vars.put('newDate', Date.parse('MMM. yyyy', vars.get('testxp1')).format('MM/d/yyyy')) – Dmitri T Oct 12 at 12:29
  • It worked. Thank you for your kind help... – Nitish Oct 15 at 8:30
  • Can you please help me in modifying code in a way to get Nov. 2015 to 11/30/2015? – Nitish Oct 15 at 11:30

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.