How to add days & years to current date

//Add to the import section of your test case or use "CTRL+SHIFT+O" to have Katalon add it for you.
import java.text.SimpleDateFormat

//Add to the body of test case
SimpleDateFormat sdf = new SimpleDateFormat(“MM/dd/yyyy”);
Calendar c = Calendar.getInstance();
c.setTime(new Date()); //Use today’s date
c.add(Calendar.DATE, 2); //Adds # of days
c.add(Calendar.YEAR, 2); //Adds years
String currentDate = sdf.format(c.getTime());
System.out.println("Future Date (MM/DD/YYYY): " + currentDate);

Time examples can be found here:

5 Likes

You can also achieve the same thing with much less code if you just want the currentDate

import java.util.Date

today = new Date()
String requestDate = today.format(‘MMM dd, yyyy HH:mm’);
println(requestDate);

This outputs ex: Nov 20, 2019 10:45

There are tons of resources online for changing the format to your liking

1 Like

Thanks for sharing :slight_smile:

1 Like