Hello All,
In one of our PAM process, developed by our ex-developer, I am trying the following code to get back the date string in form of m/dd/yyyy (for eg. 5/10/2018).
Here, our objective is to get a date string (for e.g. 5/10/2018) from database table, increment the date with 7 days (such as, 5/17/2018) and insert this incremented date string into database table.
Here, date field in table is of VARCHAR2 type.
/********** code snippet*************/
1.
2. function addScheduleNextStartDate(existingStrtDt){
3. var datestr = existingStrtDt;
4. var curr_date = new Date(datestr);
5.
6.
7.
8. var mm = curr_date.getMonth(curr_date.setMonth(curr_date.getMonth()+1));
9. var dd = curr_date.getDate(curr_date.setDate(curr_date.getDate()+7));
10. var y = curr_date.getFullYear(curr_date.setFullYear(curr_date.getFullYear()));
11. var newDatetoSet = mm+"/"+dd+"/"+y;
12. return newDatetoSet;
}
//here 'startdt' is a date string (for eg. 5/10/2018) and 'scheduleNextStartDate' is a dataset of string type
13. scheduleNextStartDate = addScheduleNextStartDate(Process.RequestList[j].startdt);
/*** Code end****/
I am getting following output here in 'scheduleNextStartDate' as 00/17/2018
Here, I am getting month as 00
For trial, I swap the code (i.e. line number 8 and 9) as below,
var mm = curr_date.getDate(curr_date.setDate(curr_date.getDate()+7)); //here I tried to call getDate()
var dd = curr_date.getMonth(curr_date.setMonth(curr_date.getMonth()+1)); //here I tried to call getMonth()
var y = curr_date.getFullYear();
In this case for date string '5/10/2018' I am getting output as '00/5/2018' for var newDatetoSet = mm+"/"+dd+"/"+y;
As we can see,
In 1st case, I was getting month as 00.
and in 2nd case, I am getting date as 00
I tried to investigate this in every possible way, but I am failing to identify where/what am I doing wrong?
I also tried generating a date with the help of Date() and then using formatDate(date,'M/dd/yyyy') in order to get the date string. But in every case the output scenario is the same.
For testing purpose, I created a separate test process in which I am passing a date string, say 5/13/2018 from one JS operator to another JS operator. In second JS operator I tried the same code and here I am getting an expected output, i.e. 5/20/2018.
Any suggestion or solution will be of great help.
Thanks and Regards!
Aniket Khandar