How to set seconds in datetime at 00 value in backend and portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2019 03:31 AM
how to set default the seconds field in the date time picker to zero all of the time. Could anyone help me how to accomplish it..
thanks
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2019 04:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 09:08 AM
to make secondo 00, we had uses this script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var dt=newValue;
if(dt.slice(-2)!='00'){
g_form.setValue('u_date',dt.toString().slice(0,-2)+"00");
}
//
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 09:10 AM
I was looking for something similar.
Here is the client script I used to set seconds to 00 and round the minutes to the nearest quarter hour.
This should give a base to start from.
This is best set in an onChange script for the date and time field you want to modify.
// Rounds seconds to 00 and minutes to the nearest quarter hour
var startDateTime = new Date(g_form.getValue("planned_start_date"));
var roundQuarterHour = ("0" + (((startDateTime.getMinutes() + 7.5)/15 | 0) * 15) % 60).slice(-2);
var roundedTime = startDateTime.getFullYear() + "-" + ("0" + (startDateTime.getMonth() + 1)).slice(-2) + "-" + ("0" + startDateTime.getDate()).slice(-2) + " " + ("0" + startDateTime.getHours()).slice(-2) + ":" + roundQuarterHour + ":" + "00";
g_form.setValue("planned_start_date", roundedTime);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2022 01:04 PM
I have updated my script to work much better now.
You can find it here:
https://www.servicenow.com/community/developer-forum/how-to-set-seconds-to-00-and-round-to-quarter-h...