Hi Folks,
The following gives me the current date (12/18//2023) in Katalon Recorder 5.9.0:
Command|Target|Value
storeEval | new Date().toLocaleDateString(); | currentDate
echo | ${currentDate} |
Question 1: Using the same command how can I create a past date like 01/01/1965.
Question 2: Using the same command how can I create a future date like 01/01/2024.
Been looking through the forum but have not found anything yet…
2 Likes
You created a formula with your SIN calculation, so can you do something with:
DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("dd.MM.yyyy")
gOldDate = java.time.LocalDate.now().minusMonths(1).minusYears(54).format(formatter)
or
DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("dd.MM.yyyy")
gFutureDate = java.time.LocalDate.now().plusDays(14).format(formatter)
The other “old” method that I use is using the Calendar library.
Edit: I also saw on a site something like:
new Date().getMonth()+1.toLocaleDateString();
2 Likes
Hi @grylion54, Thank you for the link, it helped me come up with this working solution:
storeEval | var d=new Date(); (d.getMonth()+1)+'/'+((d.getDate()+2))+'/'+(d.getFullYear()-21); | birthDate
echo | BirthDate: ${birthDate} |
storeEval | var d=new Date(); (d.getMonth()+1)+'/'+((d.getDate()+2))+'/'+(d.getFullYear()+10); | expirationDate
echo | ${expirationDate} |
3 Likes