Separate Date and Time field to get just Time value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 03:10 PM
Hi All,
I have a Field: Start Date which is a Date Time type. I need a way to separate the Date from time and get just Time value from the field
Am writing the script in Business rules.
Any input will help me solve the issue.
Thanks,
Vtred

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 03:58 PM
Hi Vt,
you can have something like this, hope this will help.
var dt = new GlideDateTime(current.start_date);
var datetimearray = dt.getDisplayValue().split(' ');
var date = dt[0];
var time = dt[1];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 06:24 PM
This is not working.
But it works in Client script, instead i need this in BR
MY BUSINESS RULE:
(function executeRule(current, previous /*null when async*/) {
var dt = new GlideDateTime(current.u_start_date);
var datetimearray = dt.getDisplayValue().split(' ');
gs.addInfoMessage(dt);
gs.addInfoMessage(datetimearray);
var date = dt[0];
var time = dt[1];
gs.addInfoMessage(date);
gs.addInfoMessage(time);
})(current, previous);
RESULT
MY CLIENT SCRIPT:
function onLoad() {
//Type appropriate comment here, and begin script below
var dateTimeStr = g_form.getValue('u_start_date');
var dateArr = dateTimeStr.split(' ');
var date = dateArr[1];
alert(date);
}
RESULT

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 07:14 PM
Hi Vt,
This should be the correct code. Apologies for missing that part.
(function executeRule(current, previous /*null when async*/) {
var dt = new GlideDateTime(current.u_start_date);
var datetimearray = dt.getDisplayValue().split(' ');
gs.addInfoMessage(dt);
var date = datetimearray[0];
var time = datetimearray[1];
gs.addInfoMessage(date);
gs.addInfoMessage(time);
})(current, previous);
Result:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 07:04 PM
Just split the string value and use the time.
var res = current.u_start_date;
var strTime = res.split(' ');
var time= strTime [1];
gs.addInfoMessage(time);