Every 4 years you may have noticed that when you do date calculations you might end up with 29 days in February. Of course this is not a bug in Workload Scheduler, but the astronomical phenomenon that is the Leap Year.

Whilst it might not be a bug, it can be problematic for scheduling. You may already know that if you add or subtract a month from a date using JCL directives and the Day does not exist in the resulting month, it gets adjusted to the highest day in the month. For example if you add one month to March 31st you get April 30th. Equally if you subtract one month from March 31st you will get February 28th in most years and February 29th in Leap Years.

But did you know that this also happens if you subtract years? You won’t see it very often as it only happens on February 29th once every 4 years, and then only if you are calculating year differences that are NOT multiples of 4. For example, if you subtract 1 year from Feb 29th 2024 you get Feb 28th 2023, with the date being adjusted to the day before the non-existent Feb 29th 2023.

Copy to Clipboard

 But what if you wanted to adjust in the opposite direction?

That’s all good if you wanted to adjust to the day before, but what if you wanted to adjust to the day after? It’s a bit more tricky, but it can be done.

Copy to Clipboard

The calculation is done exactly as before and then you check to see if you need to adjust in the opposite direction. You can tell if adjustment is needed as the Month and Day in the calculated date is not the same as the origin Month and Day. So you can extract the Month and Day from the calculated date using SUBSTR and then compare that with the origin Month and Day. Then because we KNOW this will only ever happen at the end of February, we can use SUBSTR to extract the year from the calculated date and stick 0301 onto the end to get the beginning of March instead of the adjusted end of February.

But what about offset calendars?

Whilst it’s fairly common, the whole world does not use the Gregorian calendar, or at least not the same year origin. There are calendars that still observe the leap day, but the year number has a different origin point. In these cases to convert to the local calendar requires adding or subtracting from the year BUT the resulting date should still have a Feb 29th. For example if your local calendar has an offset of 11 years, and you used SETVAR TYMD=(OYMD1-11YR) you would get 130228, when what you really wanted was 130229.

You handle this by ONLY subtracting against the Year, not the whole date and assembling your converted date from the calculated Year and the current Month and Day.

Copy to Clipboard

When performing date based calculations with Calendar/Work days, months, weeks or years the syntax of SETVAR expects the first argument to be the variable name WITHOUT the & prefix. It is important to note that because we are now doing a numeric calculation against a variable instead of a date based calculation the source variable must have the & prefix applied. For example &OYY.

If instead you wanted a four digit year you could use variable OYYYY, and if you wanted the submission date rather than the scheduled date use the C versions of each variable instead. For example &CYY, &CMM and &CDD.

Converting the results of a calculation

This technique works well for converting the current or scheduled date, but if you want to perform a calculation and then convert the result, it is a little more complicated. This is because there are no supplied variables for the Year Month and Day of the result of a calculation, so you must extract them yourself, otherwise the technique is similar.

Copy to Clipboard

In this example we want to know the converted date of a day 3 working days from now. So variable TCALC calculates the date 3 working days from now, which is then split into TYY which contains the year and TMD which contains the Month and Day. Then 11 is subtract from TYY which is then reassembled with TMD to give the desired result.