- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 02:00 AM
Does anyone have a business rule I can use as an example to convert the duration between 2 dates to minutes?
We currently have 2 date fields (dd/mm/yyyy hh:mm:ss)
u_outage_start
u_outage_end
Looking to get this converted to minutes in field u_reported_downtime_degradation
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 03:17 AM
Yes,
That is because you are setting the seconds variable and not mins, Use the below
(function executeRule(current, previous /*null when async*/) {
var dateString1 = new GlideDateTime(current.u_outage_start);
var dateString2 = new GlideDateTime(current.u_outage_end);
var diffSeconds = gs.dateDiff(dateString1, dateString2, true);
diffMins = diffSeconds/60;
current.u_reported_downtime_degradation = diffMins ;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 03:14 AM
Hi Arung,
After some testing its working out its actually calculating the seconds not minutes?
Any amendments I can make?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 03:17 AM
Yes,
That is because you are setting the seconds variable and not mins, Use the below
(function executeRule(current, previous /*null when async*/) {
var dateString1 = new GlideDateTime(current.u_outage_start);
var dateString2 = new GlideDateTime(current.u_outage_end);
var diffSeconds = gs.dateDiff(dateString1, dateString2, true);
diffMins = diffSeconds/60;
current.u_reported_downtime_degradation = diffMins ;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 03:23 AM
Of course! Can you tell its Friday? 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 03:24 AM
haha. Cheers mate!!