Description
Use a calculated variable to display a categorical amount of time between two dates of interest.
How To
Table:
The final table could look like the below image. In this example, the column of time categories designate the number of weeks before a phone call is due.
...
The JavaScript function to calculate the time days between the two dates :
function diffInDaysUTC diffInDays(a, b)
{
var milliSecondsPerDay = 1000 * 3600 * 24;
var baselineDate = Date.UTC( a.getFullYear(), a.getMonth(), a.getDate());
var followUpDate = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate())b;
var numDays = ((followUpDate - baselineDate) / milliSecondsPerDay);
return Math.floor((baselineDate - followUpDate) / milliSecondsPerDay)round(numDays);
}
The diffInDaysUTC diffInDays method calculates the number of milliseconds between the two dates (baseline and 30 day follow up date, in this case) and accounts for any time differences or time changes that may occur.and converts the number to days.
In order to convert milliseconds to days, a division of the number of milliseconds by the number of milliseconds per day is required.
...
The following code will calculate which amount of days should correspond with which particular pick list value:
var dateDifference = diffInDaysUTCdiffInDays(V3, V4);
if(dateDifference < 0) { return 0;}
else if (dateDifference <= 7 && dateDifference > 0) { return 1;}
else if (dateDifference > 7 && dateDifference <= 14) { return 2;}
else if (dateDifference > 14) { return 3;} var weeks = Math.round((dateDifference / 7) + 1);
return weeks > 3 ? 3 : weeks;
End result:
The final code in this example: