
- 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-29-2024 11:24 AM - edited 09-29-2024 06:22 PM
Hello @Virendra K
You can try below script:
var todayAtNoon = setTime(new GlideDateTime(), '12:00:00');
function setTime(oldDate, time) {
var newDate = new GlideDateTime( '1970-01-01 ' + time);
if (!newDate. isValid()) {
throw new Error( 'Invalid time provided: ' + time);
}
newDate.setYearUTC(oldDate.getYearUTC());
newDate.setMonthUTC(oldDate.getMonthUTC());
newDate.setDayOfMonthUTC(oldDate.getDayOfMonthUTC());
return newDate;
}
I hope this answer your query.
Thanks & Regards
Juhi Poddar

- 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-29-2024 09:03 PM
Hi @Virendra K
Can you please explain the logic behind this conversion ? I am not able to understand how 2024-09-28 11:15:01 becomes 2024-09-28 00:00:01 .
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 02:45 AM
Hi @Amit Verma
I am checking range of the dates. There are dates stored with timings, so if the input date is '2024-09-30 11:15:01' and actual stored records date is '2024-09-30 08:00:00' then its getting skipped while fetching it.
I want to set any input date/time like '2024-09-30 00:00:01' to '2024-10-01 11:59:59' so that whatever schedules are in between from '2024-09-30 00:00:01' to '2024-10-01 11:59:59' should be get covered while fetching the records.
Thanks,
Virendra