How to generate previous month first date in jmeter?

372 Views Asked by At

I used timeShift function (${__timeShift(yyyy-MM-01'T'00:00:00.000'Z',,-P1M,,)}) to generate the previous month first date but the jmeter was still print the current month's first date.

I also tried ${__timeShift(yyyy-MM-01,,,-P1M)} and ${__timeShift(yyyy-MM-01,,P1M,-)} but with these functions as well jmeter was printing current month's date.

How can I generate previous month's first date in jmeter using timeShift function?

1

There are 1 best solutions below

0
Dmitri T On

I don't think you will be able to use __timeShift() function for this. As per Duration.parse() javadoc

The sections have suffixes in ASCII of "D", "H", "M" and "S" for days, hours, minutes and seconds, accepted in upper or lower case.

So you're subtracting 1 minute, not 1 month.

My expectation is that you should go for __groovy() function, something like:

${__groovy(java.time.LocalDate.now().minusMonths(1).with(java.time.temporal.TemporalAdjusters.firstDayOfMonth()).format("yyyy-MM-dd'T'00:00:00.000'Z'"),)}

should do the trick for you:

enter image description here

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?