Expand my Community achievements bar.

SOLVED

Make Date Selection fall on the next Saturday

Avatar

Level 3

How can I make a date selected to fall on the next saturday of that week?

This means that if a user selects today 24th on a date field, I want Saturday 30th to show in the date field.

How can I script this?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 7

try this in the exit event of the calendar in formcalc:

var originalDate = Date2Num($.formattedValue, "DD/MM/YY")

var dayOfWeek = Num2Date(originalDate, "E")

var newDate = 7 - dayOfWeek

if (dayOfWeek < 7) then

$ = Num2Date((originalDate + newDate),"DD/MM/YY")

endif

just make sure your pattern for the calendar is DD/MM/YY (or adjust the code to whatever your pattern is).

View solution in original post

3 Replies

Avatar

Correct answer by
Level 7

try this in the exit event of the calendar in formcalc:

var originalDate = Date2Num($.formattedValue, "DD/MM/YY")

var dayOfWeek = Num2Date(originalDate, "E")

var newDate = 7 - dayOfWeek

if (dayOfWeek < 7) then

$ = Num2Date((originalDate + newDate),"DD/MM/YY")

endif

just make sure your pattern for the calendar is DD/MM/YY (or adjust the code to whatever your pattern is).

Avatar

Level 3

Unfortunately whyisthisme,

your code does not work. the result is '07/01/00' no matter what date is chosen.

Please test again and help

Avatar

Level 3

Sorry,

the script was very helpful. I forgot to change to 'formcalc'

thanks a ton.