Cognito-forms – Use calculation to provide the next Friday based on submission date

calculatorcognito-forms

I will have our users input "today's" date on a form, and I want the next field to auto-populate to the next Friday:

So if the submission date is 9/25/2017, the calculated field would be 9/29/2017.
Or if the submission date is 9/29/2017, the calculated field would be 9/29/2017.

Is there a way to use the default date in a date field, or a calculation field to make this happen?

Best Answer

I'm a developer with Cognito Forms.

You can use the following calculation in a second Date field, that is targeting another date field. By targeting the first Date will be used to enter in the current date.

=if(Today.DayOfWeek == "Friday") then Today else if(Today.DayOfWeek == "Saturday") then Today.AddDays(6) else if(Today.DayOfWeek == "Sunday") then Today.AddDays(5) else if(Today.DayOfWeek == "Monday") then Today.AddDays(4) else if(Today.DayOfWeek == "Tuesday") then Today.AddDays(3) else if(Today.DayOfWeek == "Wednesday") then Today.AddDays(2) else Today.AddDays(1)

You can then set the second Date field that is using this calculation, to hidden or internal. Then create a calculation field that targets the second date field and display's the value.

You can see this in action in a template that we have created. This will let you copy a working template into your own Organization.

https://www.cognitoforms.com/templates/shared/CognitoFormsTemplateDemo/NextFriday