Expand my Community achievements bar.

SOLVED

Adding number of weekdays to a date

Avatar

Level 1

I currently have the following formcalc code in place that adds a number of days (based on a different calculation 'TotalDays' field) to a date, but would like for the new date calculation to include only weekdays. 

Is there a way to do this?

var begindate=Date2Num(xfa.resolveNode("SecB\.Date\.4"), "YYYY-MM-DD")

$=Num2Date(begindate+TotalDays, "YYYY-MM-DD")

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

here's a sample which will add the given numbers of weekdays to your selected date while excluding saturday and sunday.

var dp = "MM/DD/YYYY" ; date pattern

var d = Date2Num($.formattedValue, dp) ; selected date to number

var p = 9 ; Number of days to add to the selected date

for i = 1 upto p do

          d = d + 1

          while (Num2Date(d, "e") eq 6 or Num2Date(d, "e") eq 7) do

                    d = d + 1

          endwhile

endfor

DateField2.formattedValue = Num2Date(d, dp)

View solution in original post

4 Replies

Avatar

Level 5

Hope this will help you..

var begindate=Date2Num(xfa.resolveNode("SecB\.Date\.4"), "YYYY-MM-DD")

var result=Num2Date(begindate+TotalDays, "YYYY-MM-DD")

var WeekDay = Num2Date(result, "E")

Then rest of the logic....

WeekDay value must be 1,2,3,4,5,6,7

Thanks

Vijay Reddy.M

Avatar

Level 1

I'm really new to adobe designer coding.  From what I can tell your script gives me the day of the week that the resulting date would be.  Then I could say, don't allow the end result to be specific days - if I am reading it right...

I need the added # of days to not include weekends.  So if I add 9 days to the begindate and the begindate is Friday, 12/07/2012, I need it only use business/weekdays and end up being 12/20/2012.

Does your script have that potential?

Thanks!

Lisa

Avatar

Correct answer by
Level 10

Hi,

here's a sample which will add the given numbers of weekdays to your selected date while excluding saturday and sunday.

var dp = "MM/DD/YYYY" ; date pattern

var d = Date2Num($.formattedValue, dp) ; selected date to number

var p = 9 ; Number of days to add to the selected date

for i = 1 upto p do

          d = d + 1

          while (Num2Date(d, "e") eq 6 or Num2Date(d, "e") eq 7) do

                    d = d + 1

          endwhile

endfor

DateField2.formattedValue = Num2Date(d, dp)