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 06:20 AM
Could you try:-
var dr=gs.dateDiff(stdEndTime,now1.getTime(),true));
gs.addInfoMessage("extra time is"+dr);
See if a non-zero value is being returned.
If so, then i think you will have to typecast the return.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2014 06:27 AM
getting 0.
if i use:
gs.addInfoMessage("extra time is"+gs.dateDiff(stdEndTime,now1.getTime(),true));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2014 06:36 AM
OK.
Use getDisplayValue() or getDisplayValueInternal() or getValue() instead of getTime() and check which one works correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2014 07:07 AM
Subhajit
please see below info messages:
end time for extra when getDisplayValue() 06-02-14 6:11 PM
extra time when getDisplayValue() used in date diff instead of getTime() is -55030 17:11:00
All i want to get the extra time if any incident is resolved after 21:00:00 (05:00 PM as per the system)
considered example incident closed @ 06:11 PM.
So m first getting the closed time from getTime() which is returning 1970-01-01 22:11:00 so using dateDiff() m setting the hard coded value of start 1970-01-01 21:00:00.
is there any other way to write gs.dateDiff(stdEndTime,now1.getTime(),false))
stdEndTime is hard coded value and which i have entered because the getTime() is returning value like 1970-01-01 HH:MM:SS.
Please help me out of this