GideDatetime giving wrong duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 01:36 AM
I am using below script to get time difference and getting duration like below image.
var gdt1 = new GlideDateTime('2024-05-28 04:20:01');
var gdt2 = new GlideDateTime();
var duration2 = GlideDateTime.subtract(gdt2, gdt1);
gs.print(gdt2);
gs.print(duration2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 01:42 AM
Hi @Kishor O ,
Please try the below:
var gdt1 = new GlideDateTime('2024-05-28 04:20:01');
var gdt2 = new GlideDateTime();
var dur = GlideDateTime.subtract(gdt1 , gdt2);
gs.print("Diff: ="+dur.getDisplayValue());
Please mark this response as correct or helpful if it assisted you with your question.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 01:49 AM
@SN_Learn How can I get the output in seconds or miliseconds?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 02:49 AM
Hi @Kishor O ,
Try this:
var gdt1 = new GlideDateTime('2024-05-28 04:20:01');
var gdt2 = new GlideDateTime();
var dur = GlideDateTime.subtract(gdt1 , gdt2);
gs.print("Diff: ="+dur.getDisplayValue());
gs.print(gdt1.getNumericValue()); //In milliseconds
gs.print(gdt2.getNumericValue()); //In milliseconds
var sec = gdt1.getNumericValue();
gs.info(sec/1000);//In seconds
Please mark this response as correct or helpful if it assisted you with your question.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 08:22 AM
Hi @Kishor O ,
Thanks for marking it as helpful.
Could you please accept it as solution and close the thread? Thanks
Mark this as Helpful / Accept the Solution if this helps.