1 2 Previous Next 27 Replies Latest reply: May 30, 2012 9:16 AM by VC RSS

    ++ Adding number of days to an existing date

    827962
      Hi Team,

      Am trying to add number of days to an existing date.

      Ex: If the date is 28-May-2012 , I need to add 15 days to it. So the final date in the item should be 12-Jun-2012.

      How do we handle this in Application Express 4.1.0.00.32.

      Would appreciate your response by 29-May-2012.

      Thank you in advance.

      Regards,
      Anitha
        • 1. Re: ++ Adding number of days to an existing date
          VC
          Hi Anitha,

          Where are you trying to add these days? in pl/sql or javascript?

          If it is javascript use dynamic actions.
          //define the array of month names
          var monthNames = [ "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
              "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ];
          var d = new Date("28-May-2012");
          //convert the string into date
              d.setDate(d.getDate()+15);
          // add 15 days
              alert((d.getDate())+"-"+monthNames[d.getMonth()]+"-"+d.getFullYear());
          var newDate = (d.getDate())+"-"+monthNames[d.getMonth()]+"-"+d.getFullYear();
          
          // set the new date into the date picker item
          $s('PX_DATE_PICKER',newDate)
          If PL/SQL

          :PX_DATE_PICKER + 15
          • 2. Re: ++ Adding number of days to an existing date
            827962
            Hi

            I tried to use PL/SQL expression, when I run the form it resulted in the following error.When I try to create a new record.

            Error computing item default value for page item P2_PLANNED_RELEASE_DATE.

            ORA-06550: line 1, column 43: PLS-00201: identifier 'P2_WPTG_START_DATE' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored

            Regards,
            Anitha
            • 3. Re: ++ Adding number of days to an existing date
              827962
              I tried to add it this way

              In P2_PLANNED_RELEASE_DATE , in the default section, :P2_WPTG_START_DATE + 15

              The value is not displayed once user enters P2_WPTG_START_DATE in the P2_PLANNED_RELEASE_DATE. I tried to check after creating the record still the value is not captured. Am a beginner.

              Regards,
              Anitha
              • 4. Re: ++ Adding number of days to an existing date
                VC
                what did you add in the default of P2_PLANNED_RELEASE_DATE

                if you are using P2_WPTG_START_DATE + 15

                then change it to
                :P2_WPTG_START_DATE
                //add colon in front
                • 5. Re: ++ Adding number of days to an existing date
                  VC
                  In P2_PLANNED_RELEASE_DATE , in the default section, :P2_WPTG_START_DATE + 15
                  default is populated only at the time of page rendering, not after the page is loaded. you need to use javascript for that

                  Are you expecting the value to change when user tabs out from a field? then use javascript/dynamic actions to chnage the value

                  Explain it more clearly Anitha
                  You have a item called P2_WPTG_START_DATE and when user enters a value and tab out from this date picker it should add the thisdate+15 into P2_PLANNED_RELEASE_DATE item is that correct?
                  • 6. Re: ++ Adding number of days to an existing date
                    827962
                    I tried to add it thay way

                    In P2_PLANNED_RELEASE_DATE , in the default section, :P2_WPTG_START_DATE + 15

                    The value is not displayed once user enters P2_WPTG_START_DATE in the P2_PLANNED_RELEASE_DATE. I tried to check after creating the record still the value is not captured. Am a beginner.

                    Regards,
                    Anitha
                    • 7. Re: ++ Adding number of days to an existing date
                      VC
                      see my question above!
                      • 8. Re: ++ Adding number of days to an existing date
                        827962
                        Yes that is correct.

                        have a item called P2_WPTG_START_DATE and when user enters a value and tab out from this date picker it should add the thisdate+15 into P2_PLANNED_RELEASE_DATE item

                        Edited by: user773506 on May 28, 2012 5:04 AM
                        • 9. Re: ++ Adding number of days to an existing date
                          VC
                          Here you go!, follow these steps

                          Edit your page > create a dynamic action > Event (Change) > selection type (item) > Item(s) (P2_WPTG_START_DATE) > click next >action (Execute javascript code) > (untick fire on page load) > In Code add below code > click next > Create
                          //define the array of month names
                          var monthNames = [ "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                              "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ];
                          var d = new Date($v('P2_WPTG_START_DATE'));
                          //convert the string into date
                              d.setDate(d.getDate()+15);
                          // add 15 days
                             // alert((d.getDate())+"-"+monthNames[d.getMonth()]+"-"+d.getFullYear());
                          var newDate = (d.getDate())+"-"+monthNames[d.getMonth()]+"-"+d.getFullYear();
                          
                          // set the new date into the date picker item
                          $s('P2_PLANNED_RELEASE_DATE',newDate)
                          Thanks,
                          Vikram Cherukuri
                          • 10. Re: ++ Adding number of days to an existing date
                            827962
                            Hi Vikram,

                            Thank you. I followed the instruction but when i enter the the date in P2_WPTG_DELIVERY_DATE in the insert form the message that is displayed in the P2_PLANNED_RELEASE_DATE is NaN-undefined-NaN.

                            Regards,
                            Anitha
                            • 11. Re: ++ Adding number of days to an existing date
                              VC
                              Hi Anitha,

                              I know you are using Internet Explorer and there are problems everywhere with IE

                              Here is the revised code that should work in all browsers
                              //define the array of month names
                              var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
                                   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                              var dateArray = $v('P2_WPTG_START_DATE').split("-");
                              for (var i = 0; i < monthNames.length; i++) {
                                   if (monthNames[i] == dateArray[1]) {
                                        var vmonth = i;
                                        dateArray[1] = vmonth;
                                   }
                                   
                              }
                              var d = new Date(dateArray[2], dateArray[1], dateArray[0]);
                              //convert the string into date
                              d.setDate(d.getDate() + 15);
                              // add 15 days
                              var newDate = (d.getDate()) + "-" + monthNames[d.getMonth()] + "-" + d.getFullYear();
                              $s('P2_PLANNED_RELEASE_DATE',newDate);
                              • 12. Re: ++ Adding number of days to an existing date
                                827962
                                Hi Vikram,

                                I still get the same error message "NaN-undefined-NaN". I tried executing it in Chrome and IE.

                                In the When Section these are the following parameters.

                                Event : Change
                                Selection Type: Items
                                Item: P2_WPTG_DELIVERY_DATE
                                Condition: No condition

                                Regards,
                                Anitha

                                Edited by: user773506 on May 29, 2012 12:23 AM
                                • 13. Re: ++ Adding number of days to an existing date
                                  VC
                                  What is the date format in the datepicker? may be give sample date value

                                  I guess it is something to with your data format

                                  Look at this working example

                                  http://apex.oracle.com/pls/apex/f?p=46417:9

                                  login: test/test

                                  If your date format is DD-MON-YYYY then use this js code
                                  //define the array of month names
                                  var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
                                       "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                                  var dateArray = $v('P2_WPTG_START_DATE').split("-");
                                  for (var i = 0; i < monthNames.length; i++) {
                                       if (monthNames[i] == dateArray[1]) {
                                            var vmonth = i;
                                            dateArray[1] = vmonth;
                                       }
                                       
                                  }
                                  var d = new Date(dateArray[2], dateArray[1], dateArray[0]);
                                  //convert the string into date
                                  d.setDate(d.getDate() + 15);
                                  // add 15 days
                                  var newDate = (d.getDate()) + "-" + monthNames[d.getMonth()] + "-" + d.getFullYear();
                                  $s('P2_PLANNED_RELEASE_DATE',newDate);
                                  • 14. Re: ++ Adding number of days to an existing date
                                    827962
                                    IE 7

                                    Google Chrome 19.0.1084.52 m

                                    Date format : DD-MON-YY
                                    1 2 Previous Next