How to add the seconds to the date and time ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 08:05 AM
HI,
I am running the below code in the background script , but resulting as undefined. Could someone please help me to resolve this .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 09:07 AM
Hi @snow57 ,
you can't get time difference for string fields and use below script.
var d1 = '2023-09-22 21:13:58';
var d2 = '2023-09-22 21:43:58';
var d3 = '2023-09-23 21:43:58';
var gdt1= new GlideDateTime(d1);//need to conveet into glidedatetime
var gdt2= new GlideDateTime(d2);
var gdt3= new GlideDateTime(d3);
var dur=new GlideDateTime.subtract(gdt1,gdt2);
var secs=dur.getNumericValue()/1000;//get the difference in seconds
gdt3.addSeconds(secs);
gs.info(gdt3.getValue());
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 09:16 AM
Hi Pavan,
Thanks for responding. I am able to get the difference in seconds. But i cant add that seconds to the other date. Could you please help me on this.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 08:17 PM
Hi @snow57 ,
I used the same script and able to add secs to date please refer below screenshot.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 01:49 PM
Hi Pavan,
Thanks for helping me on this. Suppose after adding if i want to set in date and time variable by formatting . It is not resulting the expected result.
Regards,
snow.