Cognito-forms – How to calculate the week ending date based on a given date

cognito-forms

Week ends on Sunday. So today, Friday, has week ending date DateTime.Today.AddDays(2), correct?

And in general, if I calculate the number of days from the given date until the week ending date and assign it to DaysToWeekEnding (number value), then

DateTime.Today.AddDays(DaysToWeekEnding) , right?

Well I keep getting an error when trying to set the default value of a date field to the above. "No applicable method 'adddays' exists in type 'DateTime'. But if I replace DaysToWeekEnding with a literal number (e.g. 2), then the form builder accepts it as valid.

Please help me out of this loop, or let me know of another way to obtain a week ending date.

Best Answer

I think you specifically need to convert that number (DaysToWeekEnding) into an integer. So your calculation should look like this:

=DateTime.Today.AddDays(Int32.Parse(DaysToWeekEnding))

I hope this helps to get you out of that loop.