How to set seconds in datetime at 00 value in backend and portal

njenga
Kilo Contributor

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

4 REPLIES 4

tiagomacul
Giga Sage

 

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");
}
//
}

Zach Wehrli
Tera Contributor

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);

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...