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

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments

Calculate weekend days


Level 2


I know there is a discussion about this here already (Calculate the number of week days between two dates)

but I couln't reply to it so therefore I choose to do like this....

I've tried the script (FormCalc) as described in this discussion but it won't work... Can someone please help me and se where I've got it wrong??

If I choose the start date to a friday and the end date to sunday the week after I've got 2 weekend days (it should be 4). The totalsum is ok but I can't get the weekend-days to be correct.

I've tried to change the numbers (1-7) but that won't help so something else must be wrong....

I couln't attach the file so I hope it will do like this.


Tyoe: Date/Time Fiekd, Display pattern: date{EEEE, YYYY-MM-DD},Edit, Validation and Data pattern: date{YYYY-MM-DD}, Visible, Locale: Swedish (Sweden), Value UserEntered - Optional, Binding: Start_Date1


Same as StartDate but of course named EndDate instead.

Weekend Days:

The field is TextField, No Pattern, Visible, Locale: Swedish (Sweden), Value: type: Calculated - Read Only, Calculation Script, Binding: WeedEndDays

The script for weekend days:

form1.Page1.subform1.WeekEndDays::calculate - (FormCalc, client)

if (HasValue(Start_Date1) & HasValue(End_Date1) ) then

  if (Date2Num(End_Date1, "YYYY-MM-DD", "sv_SE") > Date2Num(Start_Date1, "YYYY-MM-DD", "sv_SE")) then

  var TotalDays = Date2Num(End_Date1, "YYYY-MM-DD", "sv_SE") - Date2Num(Start_Date1, "YYYY-MM-DD", "sv_SE") + 1

  var currentDateNum = Date2Num(Start_Date1.formattedValue,"YYYY-MM-DD")

  var dayCnt = 0

  for i=1 upTo TotalDays do

  var dayOfWeek = Num2Date(currentDateNum,"E")

  if (dayOfWeek == 6 | dayOfWeek == 7) then

  dayCnt = dayCnt + 1


  currentDateNum = currentDateNum + 1


  $ = dayCnt







0 Replies