set the time in a date/time field on record producer HH:mm:ss seconds set to 00

LePhucTanT
Giga Expert

Hello community!

I have a question about the date/time field on a record producer. 
Currently this field is draws time in the format of HH:mm:ss. Main issue with this is when users use Calendar to select date, the time is automatically filled to the current time. Including the seconds. 
This causes issues when this selection is used to book in a slot of time.
E.G, 
when user books from 13:00:02 until 14:00:02, when another user wants to book in 14:00:00 until 15:00:00, it would say the timeslot is not available. 
It wouldn't be a good system if I have to have a label that says " please round off your times to the nearest minute"
So I was trying to find a way to make it so when a date/time is inputted into the field. this would trigger to always change the seconds into 00. Wondering if anyone else has ever had this issue, and how they have resolved it in the past. OR have any suggestions on how to do this that would be appreciated. 


1 ACCEPTED SOLUTION

KrishnaMohan
Giga Sage

Hi @LePhucTanT 

 

We can set value of field when datetime field changes, for that you can use below on change client script in record producer.

 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   if(newValue){
	var dateTime = newValue; //dateTime = `2025-02-14 10:20:30`  where `slot` is date time field in record producer
    var dateTimeArray = dateTime.split(" ");   // ["2025-02-14","10:20:30"]
    var timeArray = dateTimeArray[1].split(":");  // [ '10', '20', '30' ]
    timeArray[2] = "00";   // time = [ '10', '20', '00' ]
    dateTimeArray[1] = timeArray.join(":"); // dateTimeArray = ["2025-02-14","10:20:00"]
    g_form.setValue("slot",dateTimeArray.join(" "));  //2025-02-14 10:20:00
	return;
   }
 
}

 

 

 

KrishnaMohan_0-1739420337900.png

 

Output : 

KrishnaMohan_2-1739420549904.png

 

 

If this helps, please mark this as correct/helpful.

 

Regards,

Krishnamohan

View solution in original post

4 REPLIES 4

KrishnaMohan
Giga Sage

Hi @LePhucTanT 

 

We can set value of field when datetime field changes, for that you can use below on change client script in record producer.

 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   if(newValue){
	var dateTime = newValue; //dateTime = `2025-02-14 10:20:30`  where `slot` is date time field in record producer
    var dateTimeArray = dateTime.split(" ");   // ["2025-02-14","10:20:30"]
    var timeArray = dateTimeArray[1].split(":");  // [ '10', '20', '30' ]
    timeArray[2] = "00";   // time = [ '10', '20', '00' ]
    dateTimeArray[1] = timeArray.join(":"); // dateTimeArray = ["2025-02-14","10:20:00"]
    g_form.setValue("slot",dateTimeArray.join(" "));  //2025-02-14 10:20:00
	return;
   }
 
}

 

 

 

KrishnaMohan_0-1739420337900.png

 

Output : 

KrishnaMohan_2-1739420549904.png

 

 

If this helps, please mark this as correct/helpful.

 

Regards,

Krishnamohan

This works perfectly!
it was able to split the date and time, then change the value of ss every time the field was updated 
appreciate your assistance. 

Regards
Tim

Worked perfectly first time by being both correct and helpful. 

Thank you.

 

Reagrds

Stef

Tai Vu
Kilo Patron
Kilo Patron

Hi @LePhucTanT 

 

 

Yes, the seconds in a Date/Time field default to the current time when using the calendar picker. Let try my onChange client script below to reset seconds to 00 after selection:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if (newValue.endsWith('00')) {
        return;
    }

    g_form.setValue('outage_start', newValue.slice(0, -2) + '00');

}

 

 

Cheers,

Tai Vu