Calculating date as today + months

Hi everybody!
I want to code a question that just shows the interviewer the date of today+2months, which is the maximum date the have to do an activity. Do any of you have an idea on how to do that? :slight_smile: Thanks!

You probably first need to be specific as to what precisely constitutes a 'month'? eg 30 days? 31 days? 28 (or 29?!) days? or 4 weeks? or whatever the same day # in the next month, etc. This will directly influence the complexity of the solution required.

You should also consider (all!) potential edge cases. eg what is "2 months" after Dec 31?

FWIW, if you can make a 'month' be 4 weeks/28 days, the solution can be a simple calculation. Otherwise, perhaps see Calculate age in years, months and/or days for, um, 'inspiration' :grin:

1 Like

Hi! Thank you so much for responding ^^ I think 60days should be good. After dec 31 i would expect the calculation to be 60 days after, in the next year. Can you enligghten me on the type of calculation I could use? The 'inspiration' you sent is.. quite a handful jajaja

Try this and adapt to your needs:

SimpleForm copy.xlsx (14.2 KB)

Screenshot 2024-07-26 at 8.33.11 AM

Basically, the trick is first convert your start date [I'm just using now(), but it could just as easily be a user specified date question] to a number of days, using the decimal-date-time() function. Then add (or subtract!) to this number however many days you want for the duration; in your case +60. Then convert this new number of days back into a date, using the inverse date() function. ie

end = date(decimal-date-time(now())+60)

I've also tidied up the end date just for display purposes (using format-date()) but this is entirely optional and doesn't affect the calculation.

Sounds awesome! Thank you very mcuh for your help!!