pramod_pams
pramod_pams

Reputation: 3

__timeShift function not returning the previous year date

I'm using the __timeShift function as follows

${__timeShift(YYYY-MM-dd hh:mm,,-P7D,,)}

My current date is 3rd of January 2023. I'm expecting 2022-12-27 02:13 but getting output as 2023-12-27 02:13.

If my current date is 10th of January 2023, then I should get output as 2023-01-03 02:13. So I should be able to get the date 7 days previous to current date.

I'm not sure how to give the formatting and options in __timeShift function to have proper date. Please do help me in this.

Here is what I have tried... Link to Img

Upvotes: 0

Views: 196

Answers (3)

Ashish Namdeo
Ashish Namdeo

Reputation: 1

Issue is still there in Jmeter 5.5, when I try ${__timeShift(YYYY-MM-dd,,P-58D,,)} on 27-Feb-2025, it returns 31-Dec-2025

other values that I tried :-

${__timeShift(YYYY-MM-dd,,P-57D,,)}, returns 2025-01-01 which is correct
${__timeShift(YYYY-MM-dd,,P-58D,,)}, returns 2025-12-31 which is incorrect
${__timeShift(YYYY-MM-dd,,P-59D,,)}, returns 2025-12-30 which is incorrect
${__timeShift(YYYY-MM-dd,,P-60D,,)}, returns 2025-12-29 which is incorrect
${__timeShift(YYYY-MM-dd,,P-61D,,)}, returns 2024-12-28 which is correct

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168147

I cannot reproduce your issue using latest stable JMeter 5.5 and the following __timeShift() function syntax:

${__timeShift(YYYY-MM-dd hh:mm,,-P7D,,)}

enter image description here

so double check your operating system date and ensure you're using the latest stable JMeter version which is available at JMeter Downloads page.

Upvotes: 0

abhinavsinghvirsen
abhinavsinghvirsen

Reputation: 2044

${__timeShift(YYYY-MM-dd hh:mm,,-7D,,)}

This will shift the current date backwards by 7 days, and the output will be in the format YYYY-MM-dd hh:mm, as specified by the first parameter.

If you want to include the time in the output, you can specify the current time using the __time function, like this:

${__timeShift(YYYY-MM-dd hh:mm,${__time(hh:mm)},-7D,,)}

Upvotes: 0

Related Questions