
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2024 10:47 AM - edited 09-29-2024 10:47 AM
Hi All,
I am collecting Dates input in client script and passing it to script include.
Client script:
SI :
var plannedStart = new GlideDateTime(this.getParameter("sysparm_startDt"));
var plannedEnd = new GlideDateTime(this.getParameter("sysparm_endDt"));
Take an example, I am getting dates like,
'2024-09-28 11:15:01'
'2024-09-29 15:10:00'
But I want to set /customise only Time format of above fetched date like,
'2024-09-28 00:00:01'
'2024-09-29 11:59:59'
How I could do it either in client or server side script ?
Thank you.
Regards,
VIrendra
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2024 07:33 PM
@Virendra K I didn't get the exact requirement but here are two solutions.
If you just want to update the time part of a date to a different time.
// Assume we have a GlideDateTime object
var gdt = new GlideDateTime("2024-09-30 10:00:00");
// Let's change only the time to 16:45:00, keeping the same date
gdt.setDisplayValue(gdt.getDisplayValue().split(" ")[0] + " 16:45:00");
gs.info("Modified Date/Time: " + gdt.getDisplayValue());
OR
If you want to update the date object by adding time in it.
// Create a new GlideDateTime object
var gdt = new GlideDateTime();
// Add 2 hours to the current time
gdt.addSeconds(2 * 60 * 60);
gs.info("Updated Date/Time after adding 2 hours: " + gdt.getDisplayValue());
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 04:28 AM
Hello @Virendra K
To change only the time format for a given date, you can refer the below code:
var startDate = new GlideDateTime("2024-09-29 10:00:00");
var endDate = new GlideDateTime("2024-09-30 11:00:00");
startDate.setValue(startDate.getDisplayValue().split(" ")[0] + " 00:00:01");
gs.log(startDate);
endDate.setValue(endDate.getDisplayValue().split(" ")[0] + " 11:59:59");
gs.log(endDate);
Thank You
Juhi Poddar