ETL Workflow to Calculate Future Date Based on Number of Days, Excluding Weekends & Public Holidays

Overview

This entry explains how to configure ETL logic to calculate a future date based on a specified number of days, while excluding weekends and public holidays. The approach is based on timestamps and calendar-aware hour counting. The ETL first calculates an estimated end timestamp, then uses the Hour Counter step with configured calendars to determine whether the range contains the required number of valid hours. If the counted hours are less than expected, the end timestamp will be extended.


Prerequisites

Before configuring the ETL, ensure the required Scheduler calendars have been created.

Example calendars:

  • Weekends
    Represents Saturday to Sunday, full day.
  • Public Holidays
    Represents the applicable public holiday dates.

Please refer to the following support entry for further details on creating calendars from the Scheduler module: Configuring Scheduler Calendars for Weekends and Public Holidays - Ambience 2020+ - Elixir Support Forum


Source Data Requirements

Each JDBC record must provide the following logical values:

  • A record identifier, such as Id.
  • A valid starting date, such as startDate.
  • A positive whole number representing the required working days, such as NumberOfDays.

ETL Chainset Structure

One chainset containing two chains:

A) Dynamic Date Offset Workflow

  • Reads the JDBC records and controls the overall calculation.

B) Adjust Hours

  • Extends the estimated future date, recounts the valid working hours, and determines whether another adjustment is required.

Run the Dynamic Date Offset Workflow chain. The Adjust Hours chain is called automatically by the Do Chain While step.

image



Chain 1: Dynamic Date Offset Workflow

This is the main chain that reads the source records and returns the calculated future date.


Step 1: JDBC Definition

Select the connection pool that has already configured for the database.

Define the record identifier, starting date, and number of days from SQL Server.

SELECT
    StartDate AS startTimestamp,
    NumberOfDays
FROM ETLDateDemo.dbo.DateCalculation
ORDER BY Id;

Step 2: JDBC Reader

Add a JDBC Reader step to return each database row as an ETL record.

Verify the field names and types in the Results panel:

  • Id should identify the source record.
  • startTimestamp should be a long integer containing epoch milliseconds.
  • NumberOfDays should be an integer suitable for multiplication.

Note:

Field names are used throughout the chain. Keep their capitalization consistent. For example, NumberOfDays and numberOfDays should not be treated as interchangeable unless all downstream steps are updated to use the chosen name.

If the JDBC Reader returns no records, verify the selected pool, SQL statement, database permissions, and any WHERE conditions before continuing.


Step 3: String Add Suffix

Add a String Add Suffix step to append the required time component and UTC+08:00 offset to startTimestamp.

  • Field: startTimestamp
  • Value: T00:00:00+08:00

For example:

Before: 2026-07-16
After:  2026-07-16T00:00:00+08:00

This converts the date text into a complete ISO 8601 timestamp representation. The appended components represent:

T00:00:00  = Midnight
+08:00      = UTC+08:00 time-zone offset

The +08:00 offset should correspond to the applicable business time zone. Update this value if the source records use a different time-zone offset.


Step 4: Parse String

Add a Parse String step to convert the timestamp text into an actual Date-Time value.

  • String Field: startTimestamp
  • Format: yyyy-MM-dd’T’HH:mm:ssXXX
  • Locale: System Default
  • To Field: startTimestamp

The Parse String step interprets each part of the text according to the supplied format:

yyyy     = Four-digit year
MM       = Two-digit month
dd       = Two-digit day
'T'      = Literal T separator
HH       = Hour using the 24-hour clock
mm       = Minutes
ss       = Seconds
XXX      = Time-zone offset containing a colon, such as +08:00

Important: The configured format must match the source value exactly. For the value 2026-07-16T00:00:00+08:00, use yyyy-MM-dd'T'HH:mm:ssXXX.


Step 5: Change Field Type

Add a Change Field Type step to convert the parsed Date-Time value into an Int64 Unix epoch timestamp expressed in milliseconds.

  • Convert Field: startTimestamp
  • To: Int64

This additional conversion is required because the subsequent Long Integer Add step performs numeric timestamp arithmetic. A Date-Time value can be understood and displayed as a date, but it cannot be used directly as the input to a Long Integer Add operation. Converting it to Int64 provides the numeric millisecond value required by the calculation.

Important: Use Int64, not Int32. Epoch-millisecond values contain 13 digits and exceed the maximum Int32 value.


Step 6: Long Integer Add

Create an internal timestamp for the day after the starting date.

  • Field: startTimestamp
  • Value: 86400000
  • Output: nextDayTimestamp

Note:

86400000 = 24 x 60 x 60 x 1000

The Hour Counter step will utilize the nextDayTimestamp instead of startTimestamp. This ensures that the original starting date is not counted as day one.

The original startTimestamp is kept unchanged for the final output. nextDayTimestamp is an internal calculation field and will be removed at the end of the workflow.

Business-rule example:

startDate = 2026-07-16

NumberOfDays = 1

Counting begins from 2026-07-17.

If the user’s business rule should count the starting date as day one, do not add this one-day offset. The remainder of this guide assumes that counting begins on the following day.


Step 7: Integer Multiply

Convert the number of working days into the required number of valid hours.

  • Field: NumberOfDays
  • Value: 24
  • Output: targetHours

Example:

7 days x 24 hours = 168 targetHours

targetHours is the termination target used by the loop. Do not hardcode a value such as 168. It must be calculated from the NumberOfDays field so that each JDBC record can use a different value.


Step 8: Integer Multiply

Convert the number of days into milliseconds for the initial end-date estimate.

  • Field: NumberOfDays
  • Value: 86400000
  • Output: daysMs

This value creates only the first calendar-date estimate. It does not yet account for the Scheduler exclusions.

The example uses the Integer Multiply step because the demonstrated values are small. If the implementation allows very large NumberOfDays values, confirm that the selected numeric type can hold the resulting millisecond value without overflow.


Step 9: Long Integer Add Field

Calculate the initial estimated end timestamp.

  • Field 1: nextDayTimestamp
  • Field 2: daysMs
  • Output: endTimestamp

This operation produces an initial estimate before weekends and public holidays are considered.

For example, when nextDayTimestamp is Friday and NumberOfDays is 3, the initial estimate may include Saturday and Sunday. This is expected.


Step 10: Long Integer Subtract

Subtract 1000 milliseconds to close the inclusive time range at 23:59:59 on the estimated end date.

  • Field: endTimestamp
  • Value: 1000
  • Output: endTimestamp

This operation subtracts one second from the calculated timestamp boundary.

Example:

Calculated boundary: 2026-07-18 00:00:00

After subtracting 1000 milliseconds: 2026-07-17 23:59:59

This enables the Hour Counter to evaluate complete 24-hour date ranges without including the first instant of the following date.


Step 11: Hour Counter

Count the valid hours in the initial date range.

  • From Field: nextDayTimestamp
  • To Field: endTimestamp
  • Result Field: countHours

Calendar configuration:

  • Exclude: Weekends
  • Exclude: PublicHolidays

The output field countHours contains the valid hours remaining after the excluded calendars have been applied.


Step 12: Do Chain While

Call the Adjust Hours chain automatically until the required number of working hours has been reached.

  • Chain Name: Adjust Hours
  • Test Field: needsAdjustment
  • Max Loops: 20

The Do Chain While step examines the boolean needsAdjustment field returned by the Adjust Hours chain.

  • If needsAdjustment is true, the updated record is passed into Adjust Hours again.
  • If needsAdjustment is false, the loop stops and processing continues to the next step.

Max Loops is only a safety limit. It does not mean that every record runs 20 times. If a record needs three adjustments, the loop stops after the third adjustment.


Step 13: Equal Field

Validate that the final number of counted hours matches the required target hours.

  • First Field: countHours
  • Second Field: targetHours
  • Result Field: calculationComplete

Compare:

countHours = targetHours

The expected value of calculationComplete is true. This check provides a final safeguard after the loop. Once the true condition is met, the current endTimestamp is validated and established as the calculated future date with weekends and public holidays excluded.


Step 14: Change Field Types

Once the final endTimestamp has been calculated, convert the timestamp fields to Date-Time format.

a) For startTimestamp:

  • Convert: startTimestamp
  • To: Date-Time

b) For endTimestamp:

  • Convert: endTimestamp
  • To: Date-Time

Only convert the fields after the loop is complete. The arithmetic and comparison steps require the timestamp values to remain in their numeric epoch-millisecond form for the calculation.


Step 15: Local Formatted String

Format the starting timestamp for readability.

  • From Field: startTimestamp
  • Format: yyyy-MM-dd
  • Locale: System Default
  • To Field: startTimestamp

The System Default option is appropriate when the server’s locale meets the required output settings. Where a different locale is specified, the corresponding locale should be applied. The custom format yyyy-MM-dd ensures that the date is presented clearly and unambiguously in year-month-day order.


Step 16: Local Formatted String

Format the calculated future timestamp for readability.

  • From Field: endTimestamp
  • Format: yyyy-MM-dd
  • Locale: System Default
  • To Field: endTimestamp

The System Default option is appropriate when the server’s locale meets the required output settings. Where a different locale is specified, the corresponding locale should be applied. The custom format yyyy-MM-dd ensures that the date is presented clearly and unambiguously in year-month-day order.


Step 17: Discard Fields

Remove the internal calculation fields that are not required in the final output.

Fields to discard:

nextDayTimestamp
daysMs
targetHours
countHours
missingHours
missingMs
needsAdjustment
calculationComplete

The final output retains:

Id
startTimestamp
NumberOfDays
endTimestamp

Step 18: Rename Field

Rename the calculated endTimestamp field so that it matches the future-date column in the target database table.

  • From: endTimestamp
  • To: FutureDate

In this example, the target database column is named FutureDate . The corresponding ETL field must therefore be renamed to FutureDate before the JDBC Updater step runs to ensure accurate field-to-column mapping.


Step 19: JDBC Updater

Update the calculated future date in the source database table.

Example configuration:

  • Database / Pool: ETL-Mssql
  • Table: DateCalculation
  • Columns: FutureDate
  • Success Chain: Leave blank, or select a user-configured success-handling chain.
  • Failure Chain: Leave blank, or select a user-configured failure-handling chain.
  • Log Every: 100


Chain 2: Adjust Hours

The Adjust Hours chain performs one adjustment, recounts the valid working hours, and returns needsAdjustment to the Do Chain While step.


Step 1: Integer Subtract Field

Calculate the number of valid hours that are still missing.

  • Field 1: targetHours
  • Field 2: countHours
  • Output: missingHours

Calculation:

missingHours = targetHours - countHours

Example:

targetHours = 168
countHours = 120

missingHours = 48

This step must use the latest countHours value returned by the preceding Hour Counter. Reversing Field 1 and Field 2 would produce a negative value and extend the timestamp incorrectly.


Step 2: Integer Multiply

Convert the missing hours into milliseconds.

  • Field: missingHours
  • Value: 3600000
  • Output: missingMs

Note:

3600000 = 60 x 60 x 1000

This is the number of milliseconds in one hour.


Step 3: Long Integer Add Field

Extend the estimated end timestamp by the missing number of hours.

  • Field 1: endTimestamp
  • Field 2: missingMs
  • Output: endTimestamp

This creates a new estimated end timestamp that compensates for the excluded weekends or public holidays.

The adjustment applies all outstanding hours in a single operation rather than adding one day for each loop iteration. Once the hours have been added, the subsequent Hour Counter evaluates the extended date range to determine whether any additional excluded days have been introduced.

Example:

targetHours = 168
countHours = 120
missingHours = 48

The ETL extends endTimestamp by 48 hours, then recounts the range.


Step 4: Hour Counter

Recount the valid working hours using the updated endTimestamp.

  • From Field: nextDayTimestamp
  • To Field: endTimestamp
  • Result Field: countHours

Calendar configuration:

  • Exclude: Weekends
  • Exclude: PublicHolidays

The calendar configuration must be the same as the initial Hour Counter in the main chain.


Step 5: Less Than Field

Determine whether another adjustment is required.

  • First Field: countHours
  • Second Field: targetHours
  • Result Field: needsAdjustment

Compare:

countHours < targetHours

If the result is true, Do Chain While calls Adjust Hours again. If the result is false, the required number of working hours has been reached and the loop stops automatically.


Workflow Summary

JDBC records
    |
    v
Begin counting from the following day
    |
    v
Calculate target hours and initial end timestamp
    |
    v
Count valid hours using Scheduler calendars
    |
    v
Do Chain While -> Adjust Hours
    |-- Calculate missing hours
    |-- Extend endTimestamp
    |-- Recount valid hours
    `-- Repeat while countHours < targetHours
    |
    v
Validate and format the final date

Troubleshooting

Test the workflow with values that cross both weekends and configured public holidays.

For each output record:

  • startTimestamp should remain the original starting date.
  • The startTimestamp should not be counted as the first working day.
  • endTimestamp should not fall on an excluded weekend or public holiday.
  • calculationComplete should be true before the internal fields are discarded.

For troubleshooting, temporarily disable the Discard Fields step and inspect:

targetHours
countHours
missingHours
needsAdjustment
calculationComplete

Ensure that both Hour Counter steps exclude the same Weekends and PublicHolidays calendars.


Attachment

Dynamic Future Date Calculation.zip (2.2 KB)