- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2023 09:48 PM
hello experts,
i have a glide date time value which is in "2022-11-17 02:45:00" format. I need to subtract 5 hours 30 mins from it. Can anyone tell me how to do it. I am new to Scripting.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2023 10:27 PM
Hi @Deepika54,
Try this scripts -
var dateTime = new GlideDateTime('2022-11-17 02:45:00');
var dateTimeObj = new GlideDateTime(dateTime);
dateTimeObj.addSeconds(-19800); // 5.5 hrs = 19800 seconds
gs.info("Given date-time: " + dateTime + " - after date-time: " + dateTimeObj);
Thanks,
Saagr Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2023 10:03 PM
Hi Deepika
Below script will be helful for you.
var dateField = new GlideDateTime('2021-05-04'); var nowTime = new GlideDateTime(); var dur = new GlideDuration(); dur = GlideDateTime.subtract(dateField, nowTime); var days = dur.getDayPart(); gs.info(days);
Mark it correct or helpful.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2023 10:06 PM
i need to subtract only the time part. not the date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2023 10:09 PM
Try below code.
var gdt = new GlideDateTime("2011-08-31 08:00:00");
var gtime1 = new GlideTime();
gtime1.setValue("05:30:00");
gdt.subtract(gtime1);
gs.info(gdt );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2023 10:27 PM
Hi @Deepika54,
Try this scripts -
var dateTime = new GlideDateTime('2022-11-17 02:45:00');
var dateTimeObj = new GlideDateTime(dateTime);
dateTimeObj.addSeconds(-19800); // 5.5 hrs = 19800 seconds
gs.info("Given date-time: " + dateTime + " - after date-time: " + dateTimeObj);
Thanks,
Saagr Pagar