How to get the next business working day's date
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-10-16 06:13 PM
We have a business scenario, in the process, there is a decision point to check if variable Date's day is Saturday, Sunday or public holiday , if yes, defer it to next Business Day(eg. Monday)
Does Blue Prism has the function to check the day of the week?
Thank you
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
22-10-16 06:00 PM
C# code implementation:
Global Code:
public static DateTime GetNextWeekday(DateTime start, DayOfWeek day)
{
int daysToAdd = ((int) day - (int) start.DayOfWeek + 7) % 7;
return start.AddDays(daysToAdd);
}
public static bool IsDaylightSavings(String zoneID)
{
DateTime dt = DateTime.Now;
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(zoneID);
return tzi.IsDaylightSavingTime(dt);
}
Code Stage: (Inputs: addHours (Number) addMinutes (Number) addSeconds (Number))
DateTime date = DateTime.Today;
bool isDST = IsDaylightSavings(""GMT Standard Time"");
if(isDST) {
TimeSpan span = new TimeSpan(0, 1 + Convert.ToInt32(addHours), Convert.ToInt32(addMinutes), Convert.ToInt32(addSeconds), 0);
output = GetNextWeekday(date + span, DayOfWeek.Monday);
} else {
TimeSpan span = new TimeSpan(0, Convert.ToInt32(addHours), Convert.ToInt32(addMinutes), Convert.ToInt32(addSeconds), 0);
output = GetNextWeekday(date + span, DayOfWeek.Monday);
}
If I ran this form myself it would output 24/10/2016 00:00:00
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
22-10-16 06:43 PM
Alternatively using native Blue Prism functionality:
Choice Stage
Choice - FormatDate(Today(), ""dddd"") = ""Saturday""
Calculation Stage if True - ToDateTime(AddDays(Now(), 2)) + MakeTimeSpan(0 ,[Hours], [Minutes], [Seconds])
Choice - FormatDate(Today(), ""dddd"") = ""Sunday""
Calculation Stage if True - ToDateTime(AddDays(Now(), 1)) + MakeTimeSpan(0 ,[Hours], [Minutes], [Seconds])
You can initialise the [Hours], [Minutes] and [Seconds] data items to 0, or provide based on time you want to defer until on Monday. Or alternatively hard code within calculation stage.
These calculation stage will then output to a DateTime data item that can be used as the input to your Defer action.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
24-10-16 08:42 PM
The correct way to do this would be to use the Blue Prism Internal - Calendars business object which contains lots of useful actions, especially for working day calculations that take bank holidays and weekends into account.
The object expects that you have a maintained calander in System Manager - which should be the case of you want to use the Blue Prism schedular within your organisation.
If you are ever finding yourself moving towards generating bespoke code to solve a problem like this I would strongly recommend asking your Blue Prism mentor or enablement manager first to ensure there is not something already provided with the product that solves your problem.
