In an iDashboards expression, you can use math functions.
- Math.abs(y1) returns the absolute value of y1
- Math.round(y1) rounds up if the fractional-part of y1 >= 0.5 and rounds down if the fractional part of y1 < 0.5
- Math.ceil(y1) rounds up to the nearest whole number
- Math.floor(y1) rounds down to the nearest whole number
Note: case matters. Make sure the function (abs, round…) are in lowercase.
If a driver leaves a location at a given start time and arrives at a destination at a given end time calculate the how many hours a driver was on the road.
Assign y1 to the start date
Assign y2 to the end date
For y3 copy in the expression below:
// number of milliseconds in one hour
var ONE_HOUR = 1000 * 60 * 60
// convert dates to milliseconds
var startDate_ms = y1.getTime()
var endDate_ms = y2.getTime()
// Calculate the difference
var difference_ms = Math.abs(endDate_ms - startDate_ms)
// convert back to hours
Here is some sample data to see what the expression would return:
For more functions you can use in the Java math library, visit http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html