Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Compute number of days between two dates in SIL

Sushma Nagaraj August 25, 2018

I have an updated field in the format mm.dd.yyyy and I have the currentDate() in sil and I need to use these two to find the number of dates between updated date an dcurrent date. But I get Unexpected error executing rule:Exception while executing SIL program >>baseline.sil<<: [SIL Error on line: 57, column: 18] Casting to INTERVAL not supported.

my code is:

date date1=parseDate("MM.dd.yyyy",updated1);
date date2=parseDate("MM.dd.yyyy ,currentDate());

number difference=date2-date1;

1 answer

1 vote
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2018

Hello,

I guess, the only way to write a function, which would return you the number of days from an interval:

function intervalToHours(interval time) {
string [] t = split(trim(time), " ");
int hours = 0;
number days = 0;
number minutes = 0;
int hoursDay = getWorkingHoursPerDay();

for(int x = 0; x < size(t); x++) {

int intTemp;
number numTemp;
if(contains(t[x], "w")) {
intTemp = replace(t[x], "w", "");
intTemp = intTemp * (24 * 7);
hours += intTemp;
}
if(contains(t[x], "d")) {
numTemp = replace(t[x], "d", "");
days += numTemp;
}
if(contains(t[x], "h")) {
intTemp = replace(t[x], "h", "");
hours += intTemp;
}
if(contains(t[x], "m")) {
numTemp = replace(t[x], "m", "");
minutes += numTemp;
}
}

hours += days * 24;
hours += minutes/60;

return hours;
}

You can divide this number of hours by the number of hours in a day and you will get the number of days

Sushma Nagaraj August 29, 2018

Thank you, shall try this one.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events