Help needed with gs.dateDiff() to calculate difference between dates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2014 05:05 AM
Hi,
I want to get difference between two fields using gs.dateDiff(field,field,false);
Here is my BR which will be executed after insert/update on table:
myFunction();
function myFunction() {
var endtime = "";
var now1 = "";
var extra_time="";
if (current.u_mon != "")
{
endtime = current.u_mon;
now1 = current.u_mon.getGlideObject();
extra_time=now1.getTime(); // returning value 1970-01-01 22:11:00
}
if(now1.getTime() >'1970-01-01 21:00:00')
{
var stdEndTime=new GlideDateTime('1970-01-01 21:00:00');
gs.addInfoMessage("Start time for extra is"+stdEndTime); //here getting correct start time which is 1970-01-01 21:00:00
gs.addInfoMessage("end time for extra is"+now1.getTime()); // here getting correct end time which is 1970-01-01 22:11:00
gs.addInfoMessage("extra time is"+gs.dateDiff(stdEndTime,now1.getTime(),false)); // here i am gettting 00:00:00 but should be 01:11:00
}
}
Date format or date and time displayed on my form is mm-dd-yy HH:MM AM/PM, for e.g 06-02-14 6:11 PM.
I am not getting where it's going wrong, appreciate your assistance
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2014 11:06 AM
Please refer to this Link:-
GlideElement - ServiceNow Enterprise Wiki
I think this will solve your purpose.
Thanks,
Subhajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 12:13 AM
Hi,
:Your code:
// gs.addInfoMessage("extra time is"+gs.dateDiff(stdEndTime,now1.getTime(),false))
:Use This Code: // make it true then its going to return valid no of seconds and gs.dateDiff( earliearDate.getDisplayValue(), laterDate.gateDisplayValue(), true)
var gDate = new GlideDateTime(stdEndTime);
var gdt1 = new GlideDateTime( date_one);
var gdt2 = new GlideDateTime(date_two);
var durationInSeconds = gs.dateDiff(gDate.getDisplayValue(), secondDate.getDisplayValue(), true);
Note: The gs.dateDiff() method is not available in scoped applications.
Thanks,
Jeet