Need to calculate duration, given schedule, in scoped app

jamieturner_now
ServiceNow Employee
ServiceNow Employee

I need to calculate the duration between two dates, given a schedule, in a scoped app and I'm really having trouble.

this is the code I'm using (sorry, first post and I forget how to put the code into the formatter);

There is a record with an 'employee' field referencing sys_user, a start_date and an end_date field.

***************

var emplSched = current.employee.schedule;

var startDate = new GlideDateTime(current.start_date);

var endDate = new GlideDateTime(current.end_date);

var schedule = new GlideSchedule(emplSched);

var dur = schedule.duration(startDate,endDate);

var days = dur.getNumericValue() /1000 /60 /60 /25;

***************

if I put 2 weeks (Monday to a week Friday), days is returning 3

I basically followed the suggestions in this post: Use DurationCalculator in scoped application?

I've tried adding the timezone but no luck...

ANY help would be appreciated! Thanks in advance!!

FYI - I've used durationcalculator a hundred times and I WISH I could use it in a scoped app!!

1 ACCEPTED SOLUTION

drjohnchun
Tera Guru

I believe that's the correct answer. In a two-week period, assuming a 40-hour week, there are 80 hours. This in duration would be 80 / 24 ~ 3.3 days.



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

Winner of November 2016 Members' Choice Award


View solution in original post

4 REPLIES 4

drjohnchun
Tera Guru

I believe that's the correct answer. In a two-week period, assuming a 40-hour week, there are 80 hours. This in duration would be 80 / 24 ~ 3.3 days.



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

Winner of November 2016 Members' Choice Award


Oh man... yes of course!... not 24 hours a day... 8! That works better.



Yikes, thanks John... too long at it and not paying attention!



Thank you!!


No problem - I do it myself all the time. Sometimes, an extra pair of eyes comes handy, especially late at night



BTW, to format script, select the script and click on Chevron > Syntax Highlighting > javascript as shown below:



find_real_file.png


When you're replying to a post, you have to first click on Use advanced editor to see the Chevron menu:


find_real_file.png