Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Get Time part from a Date/Time Field

Huodil
Tera Contributor

Hi,

Is there a way to get the time part of a Date/Time field and store it on another Time field.

Regards,

 

In this example extract the time from Scheduled Start and store it into Expected start hour.

find_real_file.png

 

4 REPLIES 4

Saurav11
Kilo Patron
Kilo Patron

Hello,

Please try the below in a onchange client script and change the field names according to yours

function onChange(control, oldValue, newValue, isLoading) {
  //If the page isn't loading
  if (!isLoading) {
    //If the new value isn't blank
    if(newValue != '') {
      var dateSection = g_form.getValue('u_start_date_time').split(' ')[0]; //Gets the Date
      var timeSection = g_form.getValue('u_start_date_time').split(' ')[1]; //Gets the Time
      //Set the value of the Date field with the date from the Date/Time field
      g_form.setValue('u_start_date', timeSection);
    }
  }
}

Please mark answer correct/helpful based on Impact

Sharvan
Giga Guru

Hi,

Please use the below.

 

var dateTimefield = g_form.getValue('expected_start');

var dateArr = dateTimefield.split(' ');

var time = dateArr[1];//Return time

var date = dateArr[0];//return date

You can replace g_form with current if you are writing a business rule

Chandra Sekhar6
Tera Guru

Hi,

Try this code

var expected_start = current.'expected_start';

var arr = expected_start.split(' ');

var time = arr[1];

Hope this works

 

shloke04
Kilo Patron

Hi @Huodil 

My recommendation here would be to write a Before Update Business Rule on your Table and use the script shared below:

BR Details:

Table Name: Select your table

When: Before Update

Condition: Scheduled Start Changes

Script:

(function executeRule(current, previous /*null when async*/) {                                  


var dt = new GlideDateTime(current.FIELD_NAME); //Replace Field Name with Scheduled Start Field 


var datetimearray = dt.getDisplayValue().split(' ');

current.FIELD_NAME = datetimearray[1]; // Replace "FIELD_NAME " with the field where you want to set the value in.


})(current, previous);

This works for me in my PDI instance.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke