How to subtract two date and time fields in server script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2024 03:45 AM
How to subtract two date and time fields in server script
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2024 03:48 AM - edited ‎05-27-2024 03:49 AM
Hi,
Here is an example
var gdt1 = new GlideDateTime("2011-08-31 08:00:00");
var gdt2 = new GlideDateTime("2011-08-31 08:00:00");
var dur = GlideDateTime.subtract(gdt1, gdt2);
gs.info(dur.getDisplayValue());
if you have a field you want to use you can pass it as an argument like below
var gdt1 = new GlideDateTime(current.<field name>);
-Anurag
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2024 04:22 AM
Hi @Kishor O ,
var gdt1 = new GlideDateTime("2024-05-28 09:00:00");
var gdt2 = new GlideDateTime("2024-05-31 18:00:00");
var dur = GlideDateTime.subtract(gdt1, gdt2); // Difference between gdt1 and gdt2
gs.info(dur.getDisplayValue());
ServiceNow Document for more details: GlideDateTime - Global
Please consider marking my reply as Helpful and/or Accept Solution, if it helps. Thanks!
----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.
Mark this as Helpful / Accept the Solution if this helps.