Convert Date Selected to the Next Tuesday Date

Hello!

Super nube here who is switching from Airtable to Knack. I am in need of some help for our course registration process. We register our students for Tuesday start dates. Is there a way to either only show Tuesday’s in the date field OR like we did in Airtable, convert the date chosen to the nearest Tuesday? Below is the formula I used to use in Airtable:

IF(2-WEEKDAY({START DATE})<0,DATEADD({START DATE},2-(WEEKDAY({START DATE}))+7,‘days’),DATEADD({START DATE},2-(WEEKDAY({START DATE})),‘days’))

Any help anyone can provide will be greatly appreciated! Thanks.

Dan Rushton

Hey @Dan3,
You’re going to need three fields here. The start date, an equation to calculate the start date day of the week, and an equation to calculate the next Tuesday.
Note that if the start date is a Tuesday, it will return the same day (e.g. start date = 19 Sep, then nearest Tuesday = 19 Sep).

image

The Day of week equation field looks like this:
getDateDayOfWeek({Start date})

The Nearest Tuesday date equation field looks like this:
{Day of week}<=3 ? {Start date}+3-{Day of week} : {Start date}+10-{Day of week}

I believe due to the nature of how the Equation field calculates either numerically or date (and not both), merging the two equation fields into one won’t work properly, so avoid trying the below:
getDateDayOfWeek({Start date})<=3 ? {Start date}+3-getDateDayOfWeek({Start date}) : {Start date}+10-getDateDayOfWeek({Start date})

2 Likes

You ARE AMAZING!!! Thank you thank you thank you!

1 Like

Hi @StephenChapman

This is great I never knew that you use a ternary statement in an equation field. This will remove the need for quite a few JavaScript functions.

Also this specific answer will solve something we have been trying to figure out for a while which is finding out if something has happened before the following weeks friday of the previous date it happened on.

Great thank you.

Yep! You can read more about it here.
Unfortunately ternary operators are only bound to numerical values, and don’t work when trying to assess if a field is blank or equals certain text.
It would be a gamechanger if they were in text formulas too.

1 Like