Get Next Business day

Hope this helps someone in the future.

Often times when scheduling things, you need to work out the next business day. Here is a simple solution that does that.

Logic goes:

  1. If it is the weekend, set it to Monday
  2. If it is before 9am - set it to today, 9am
  3. If it is after 5pm - set it to tomorrow 9am
  4. Otherwise return now

{{
if(parseNumber(formatDate(now; “E”; “Pacific/Auckland”)) >= 6;
addDays(parseDate(formatDate(now; “yyyy-MM-DD”; “Pacific/Auckland”) & " 09:00"; “yyyy-MM-DD HH:mm”; “Pacific/Auckland”); 8 - parseNumber(formatDate(now; “E”; “Pacific/Auckland”)));

if(parseNumber(formatDate(now; "H"; "Pacific/Auckland")) < 9; parseDate(formatDate(now; "yyyy-MM-DD"; "Pacific/Auckland") & " 09:00"; "yyyy-MM-DD HH:mm"; "Pacific/Auckland"); 

  if(parseNumber(formatDate(now; "H"; "Pacific/Auckland")) >= 17; addDays(parseDate(formatDate(now; "yyyy-MM-DD"; "Pacific/Auckland") & " 09:00"; "yyyy-MM-DD HH:mm"; "Pacific/Auckland"); 

  if(parseNumber(formatDate(now; "E"; "Pacific/Auckland")) = 5; 3; 1)); 

  parseDate(formatDate(now; "yyyy-MM-DD HH:mm"; "Pacific/Auckland"); "yyyy-MM-DD HH:mm"; "Pacific/Auckland")
  )
)

)
}}

1 Like

Great stuff

How do you think public holidays can be captured in the logic, which will of course be dependent on Country?

I think so. You’d either need a publically available list or construct an array of public holidays and add that to the logic. I’ll have a look next week

This is correct.

You can use a public API that specialises in public holidays. Here are a few examples from RapidAPI: rapidapi.com/search?term=holiday

@samliew

I’ve created a module for this so you can avoid all the functions and such, while allowing insertion of upcoming public holidays.

Example Output:


(today is Thursday, correctly skips to Monday when tomorrow (Friday) is specified as a holiday)

Install it here:

My Custom AppAbsolutely Free!

Save headaches and operation credits with these utility modules:

  • Chunk Text
  • Chunk Array
  • Chunk Words
  • Multiple Find & Replace
  • Collection to Array/String List
  • Execute JavaScript
  • Estimate Tokens
  • Calculate Difference Between Two Dates
  • Get Next Business Day (with holidays)
  • List Upcoming Dates of Day of Week
    and more!

@samliew

1 Like