Get Time part from a Date/Time Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 06:27 AM
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.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 06:36 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 06:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 10:51 AM
Hi,
Try this code
var expected_start = current.'expected_start';
var arr = expected_start.split(' ');
var time = arr[1];
Hope this works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 11:31 AM
Hi
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
Regards,
Shloke