Separate Date and Time field to get just Time value

vtred
Tera Contributor

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

7 REPLIES 7

Shishir Srivast
Mega Sage

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


vtred
Tera Contributor

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


find_real_file.png




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


find_real_file.png


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:


find_real_file.png



Deepak Kumar5
Kilo Sage

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