2 Replies Latest reply on Nov 9, 2011 11:44 PM by radzmar

    Adding Date/Time Field + X Number of Days - Basic Calculation Question


      I am assuming this is a basic calculation question. New to Adobe LiveCycle Forms.


      I have a simple form containing a table. The table appears as such:


      Text Formatted as Date/Time FieldsHeader 3
      Monday user wil choose the beginning date (Date/Time) this is DateTimeField1
      Tuesdaythis should calculate DateTimeField1 + 1
      Wednesdaythis should calculate DateTimeField1 + 2
      Thursdaythis should calculate DateTimeField1 + 3
      Fridaythis should calculate DateTimeField1 + 4
      Saturdaythis should calculate DateTimeField1 + 5
      Sundaythis should calculate DateTimeField1 + 6


      Calculations are performed after the date is chosen for Monday. My mind tells me the simple calculation of DateTimeField1 + 1 is not going to work (and in fact doesn't!) as it needs to change Monday to a number first. I saw on another thread the following:



      Num2Date(Date2Num(Date(DateTimeField1), "DD.MM.YYYY")+7, "DD.MM.YYYY")


      Thought this was going to get me close. No cigars though!


      Any quick help is greatly appreciated. And since I am new to this, details about what needs to be changed would be great too!



        • 1. Re: Adding Date/Time Field + X Number of Days - Basic Calculation Question
          Steve L Walker Level 5

          The attached calculates dates for next six days starting Monday. It forces the start day to be a Monday also.


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


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




          if (dayOfWeek.rawValue == "Mon") then

                    tues.rawValue = Num2Date(dayNum+1,"MM/DD/YYYY")

                    wed.rawValue = Num2Date(dayNum+2,"MM/DD/YYYY")

                    thurs.rawValue = Num2Date(dayNum+3,"MM/DD/YYYY")

                    fri.rawValue = Num2Date(dayNum+4,"MM/DD/YYYY")

                    sat.rawValue = Num2Date(dayNum+5,"MM/DD/YYYY")

                    sun.rawValue = Num2Date(dayNum+6,"MM/DD/YYYY")


                    xfa.host.messageBox("The selected date is not a Monday.")

                    tues.rawValue = null

                    wed.rawValue = null

                    thurs.rawValue = null

                    fri.rawValue = null

                    sat.rawValue = null

                    sun.rawValue = null




          • 2. Re: Adding Date/Time Field + X Number of Days - Basic Calculation Question
            radzmar Adobe Community Professional & MVP

            Here an addition for you date field.


            This FormCalc script in the exit:Event will check it the selected date is on a monday.

            If not it will go the days back until the last monday.


            var Selection = Date2Num($.formattedValue, DateFmt(2))

            var WeekDay = Num2Date(Selection, "E")

            var NewDate

            if (WeekDay eq 1) then

                      NewDate = Selection - 6

            elseif (WeekDay eq 3) then

                      NewDate = Selection - 1

            elseif (WeekDay eq 4) then

                      NewDate = Selection - 2

            elseif (WeekDay eq 5) then

                      NewDate = Selection - 3

            elseif (WeekDay eq 6) then

                      NewDate = Selection - 4

            elseif (WeekDay eq 7) then

                      NewDate = Selection - 5


                      NewDate = Selection



            $ = Num2Date(NewDate, "EEE DD.MM.YYYY")


            Hope this helps, too.