1

I need to show a date inside a form that is 3 business days from today. If today's date is Monday, March 21st, the calculated date would be Thursday, March 24th. I know that I can do that by using =DateTime.today.AddDays(3). However, if today's date is Thursday, March 24th, the calculated date would be Tuesday, March 29th, which is actually AddDays(5). How do I ignore Saturday and Sunday?

Bonus points if I can ignore holidays as well.

1

Date Calculations in Cognito Forms are extremely powerful and can handle most types of date calculations with enough effort.

The following answer assumes you have an OrderDate field that represents today's date, and are calculating a DeliveryDate that is three business days in the future.

  1. You can calculate three business days from the now using this calculation:

    Delivery Date

    =OrderDate.AddDays(if OrderDate.DayOfWeek = "Monday" or OrderDate.DayOfWeek = "Tuesday" then 3 else if OrderDate.DayOfWeek = "Sunday" then 4 else 5)

  2. For bonus points you can refine the delivery date to add an extra day for specific holidays:

    Holiday Delivery Date

    =DeliveryDate.AddDays(if OrderDate <= "7/4/2016" and DeliveryDate >= "7/4/2016" then 1 else if OrderDate <= "11/24/2016" and DeliveryDate >= "11/24/2016" then 1 else 0)

Here is a shared template demonstrating how this works: https://www.cognitoforms.com/templates/shared/CognitoSupport/SkipWeekdaysHolidays

  • The Delivery date works perfectly. The Holiday isn't quite what I need, but I hope I can get it working using a hybrid. – Karen Godin Mar 17 '16 at 18:00
  • Holiday was just a starting point. I included two dates for July 4th and Thanksgiving. You would need to add if-then options for each date you want to consider a holiday. One key point is you will have to decide for each holiday how many extra days to add, since dates like Christmas that fall on Sunday do not count and holidays on Friday would bump to the following Monday. – Jamie Thomas Mar 17 '16 at 18:08
  • Thanks Jamie. I'm trying to get one date to show, 3 business days from today, rather than a regular date and a holiday delivery date. Now, I have logic that shows the regular delivery date if it is =(+3) and the shows the holiday delivery date if it is >(+3), so that should be working ok. And for the holidays that land on a weekend, we will use either the Friday or the Monday as the holiday, so it still affects our 3 day delivery. Thanks for all your help. – Karen Godin Mar 18 '16 at 14:21
  • The way to handle this using my example is to make the first date (the initial delivery date) a hidden calculation field, and then make the second delivery date be the one that you show and use. This is important since you have to reference the intermediary delivery date calculation in the holiday calculation. You would just only show the final result to your users (and name it whatever you want). – Jamie Thomas Mar 18 '16 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.