How to set default value of date/time field 24 hours from current time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 10:52 AM
Hi,
How to set default value of date/time field 24 hours from current time and restrict the user to not select date/time for more than 72 hours from current time
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 11:47 AM
Hi Redth.
Please check this untested code
Mark Correct or helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 06:25 AM
Hi, I have used the similar code. But it's not working as per my requirement. The above code adds one day from today, but I need to take account of time too. If the current date/time is 8/11/2022 10:23:00, it should reflect 8/12/2022 10:23:00. Instead, the above script just shows 8/12/2022 00:00:00

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2022 08:44 AM
than try adding
above script will be
var date = new GlideDateTime();
date.addDaysLocalTime(1)
gs.info(date.getDisplayValue());
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 06:41 AM
Hi,
Please try below script.
var gdt = GlideDateTime();
var daysToAdd= 1;
var day = GlideDateTime(gdt);
day.addDaysLocalTime(daysToAdd);
var d = day.getDate();
var t = day.getTime();
var newFormattedDate = d.getByFormat("dd-MM-yyyy");
var newFormattedTime = t.getByFormat('hh:mm:ss');
gs.info(newFormattedDate + ' ' +newFormattedTime);
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar