- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2015 11:50 AM
Hi Everyone,
I have two date & time fields in form, I have used the duration calculator to find the difference between two date&time field values. The result i am getting from calcsheduleduration is in "seconds" but i have set this answer in another "duration" type field like days, hours format. If anyone come across this scenario please guide me to resolve this issue.
Thanks & Appreciation in Advance,
Cheers,
Narendran.D
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2015 07:37 AM
Well, just more math!
if result = 1.753, then you can convert as follows:
var days = parseInt(result,10);
var remainder = result - days;
var dec_hours = remainder * 24;
var hours = parseInt(dec_hours,10);
remainder = dec_hours - hours;
var dec_minutes = remainder * 60;
var minutes = parseInt(dec_minutes,10);
remainder = dec_minutes - minutes;
var dec_seconds = remainder * 60;
var seconds = parseInt(dec_seconds,10);
if (hours < 10) {
hours = '0' + hours.toString();
}
if (minutes < 10) {
minutes = '0' + minutes.toString();
}
if (seconds < 10) {
seconds = '0' + seconds.toString();
}
var new_result = days + ' ' + hours + ':' + minutes + ':' + seconds;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2016 04:05 AM
I would try to just GlideDateTime instead. there are many functions for calculation date & time.
For example the convert your looking for I guess you could use:
setNumericValue(milliseconds) | Sets the datetime to the number of milliseconds since January 1, 1970 00:00:00 GMT. |
You can find more info here:http://wiki.servicenow.com/index.php?title=GlideDateTime#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:52 AM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: GlideDateTime
Visit http://docs.servicenow.com for the latest product documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2016 07:35 AM
It sounds like you might just need to do some debugging. My script has been tested and works. Can you reproduce your script here and give me a sample input?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2015 12:38 PM
Here is an example:
3.64 subtract(start, end)
Gets the duration difference between two GlideDateTime values.
3.64.1 Input Fields
Parameters:
- start - (GlideDateTime) The start value.
- end - (GlideDateTime) The end value.
3.64.2 Output Fields
Returns: (GlideDuration) The duration between the two values.
3.64.3 Example
var gdt1 = new GlideDateTime("2011-08-28 09:00:00"); var gdt2 = new GlideDateTime("2011-08-31 08:00:00"); var dur = new GlideDuration(); var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2 gs.print(dur.getDisplayValue());
Output:
*** Script: 2 Days 23 Hours
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2015 11:00 AM
Thanks for the response Mike.
sorry, I have forgot to point out one additional info in my requirement, The two date&time field will hold the two different dates, i want to find the difference between those two dates excluding weekends. for this purpose only i have used schedule duration calculator but i am getting the output in seconds so am not able to set this seconds in duration field. can you guide me to convert this second into duration format?
Cheers,
Narendran.D