Verify Value is equal to 28 days prior to today's date

I am testing a modal that comes up already populated with a “from date” of today’s date minus 28 days, and a “to date” of today’s date.

I already know how to store today’s date into a variable and then verify the value in that field matches today’s date, but how do I get the value of today’s date minus 30 days so I can verify the value of the “from date”? See screenshot -

Date from = (new Date() -28)

println from.format(“dd/MM/YYYY”)

WebUI.verifyElementText(findTestObject(‘the from field’), from.format(“dd/MM/YYYY”))

@eric.oswald is using Katalon Recorder, not Katalon Studio.
He wants some solution in JavaScript, not in Groovy.
Somebody fluent in JavaScript?
How can he calcurate today minus 28 days in JavaScript?

1 Like

Hi @eric.oswald, I did a Google search for “How to subtract days from a date in JavaScript” and found hits similar to this: How to subtract days from a date in JavaScript

1 Like

FINALLY found something that works! Looks a bit crazy, but it works!

new Date(new Date().setDate(new Date().getDate() - 28)).toLocaleDateString(‘en-us’, {month: ‘2-digit’, day: ‘2-digit’, year: ‘numeric’});

Hi @eric.oswald, Great news, thanks for posting back.

1 Like