Stephen Gilmore

📆 Date math in Workday Studio

Workday September 24th, 2022 2 minute read.

Here's a quick Studio snippet that I wanted to save to avoid having to Google this ever again: How to add or subtract n number of days from a date in a Workday Studio eval expression component.

Example:

Say I needed to subtract 90 days from a date specified in a launch parameter.

// A date format object to be used throughout the project
props["dateFormat"] = new java.text.SimpleDateFormat("yyyy-MM-dd");

// Retrieve the "As of Date" launch parameter
props["lpDate"] = lp.getDate("As of Date");

// Parse the date string into a Date object
props["parsedDate"] = props["dateFormat"].parse(props["lpDate"]);

// Convert the date into a Calendar object
props["calendar"] = java.util.Calendar.getInstance();
props["calendar"].setTime(props["parsedDate"]);

// Add 90 days to the Calendar object.
// .add(java.util.Calendar.MONTH, -3) would subtract 3 months
props["calendar"].add(java.util.Calendar.DAY_OF_MONTH, 90);

// Format the new date back to 'yyy-MM-dd' format
props["newDate"] = props["dateFormat"].format(props["calendar"].getTime());

Apply it: Looping month over month

One integration I've used this for is to create a loop that increments a date by one month each time it loops and then stops at an 'end date'.

Date Loop in Workday Studio