Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

Sunday Validation

Avatar

Level 2

I have 2 date/time fields in a timesheet form.  Currently, users can pick any date they want in the first, and the second populates with a date 6 days later.  I'm not sure how to validate that the day they pick is a Sunday.  Is that possible with scripting??

Thanks in advance,

Rose.

1 Accepted Solution

Avatar

Correct answer by
Level 10

I created a sample for you ...see the attached file.

paul

4 Replies

Avatar

Level 10

Not without scripting .....you can turn the date chosen into a javascript date object and then there is a js function that will return you the day of the week for that particular date.

Paul

Avatar

Level 2

i dont have a huge knowledge of javascript. could you help me with how to do that?

Avatar

Level 10

The attached validates the first date entered is a Sunday and calculates the second date as 6 days from the first date.

// form1.page1.date1::exit - (FormCalc, client)

// Get the number of days since epoch (Jan 1, 1900).

var dateNum = Date2Num($.formattedValue,"MM/DD/YYYY")

// Convert the number of days to the full weekday name.

dayOfWeek.rawValue = Num2Date(dateNum,"EEEE")

// Calculate 6 days from the chosen date by adding 6 to the number of days since the epoch.

date2.rawValue = Num2Date(dateNum+6,"MM/DD/YYYY")

if (dayOfWeek.rawValue ne "Sunday") then

          xfa.host.messageBox("Date1 must be a Sunday.");

endif

Steve

Avatar

Correct answer by
Level 10

I created a sample for you ...see the attached file.

paul