on 07-14-2020 6:51 PM
Hi Experts,
I have a requirement to get the number of days between two dates using groovy script in cpi.
I am using the below script and it is giving me some error.
import com.sap.it.api.mapping.*;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;
import groovy.time.TimeCategory;
def String customFunc(String startDate, String endDate){
def pattern = "yyyy-MM-dd";
def startDateF = new SimpleDateFormat(pattern).parse(startDate);
def endDateF = new SimpleDateFormat(pattern).parse(endDate);
use(groovy.time.TimeCategory) {
def duration = (startDateF - endDateF).days;
}
return duration;
}
Can you please help me correct the script to the find the number of days between two dates.
hi akashenoc,
The scope of duration variable is not outside where you are returning.
Either use return inside use block or define duration outside use block.
use(groovy.time.TimeCategory){
def duration=(startDateF - endDateF).days;
return duration;
}
Hope this helps !
thanks and regards,
Praveen T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.