How to convert a string field into a date field.

Raju Singh1
Tera Expert

Hi Experts,

In the User Record, I have a field Termination Date (u_termintion_date) which is a string type. This value is populating from my AD(Active Directory) as a string Value. Screenshot provided below.

I want to convert this value to a Date value and populate the same value in the field Term Date (u_term_date) which is a Date type field.

Termination date values are a random values and every time this value will be changing for different users.

Could you please help me with the code which I need to run in the business Rule After Update.

 

What will be the script used if I use Term Date as a Date/Time Type .

Please find the screen shot below

find_real_file.png

Regards,

Raju Singh

 

 

 

9 REPLIES 9

rammohanraomadd
Kilo Guru

Hi,

 

Try with below script:

var gr = new GlideRecord("name_of_the_table");

gr.addEncodedQuery("pass_the_required_query");

gr.query();

if(gr.next()){//If to check for one record and if working fine then change it to While

var td = gr.u_termination_date.toString();

var td1 = new GlideDateTime(td);

gr.u_term_date = td1;

gr.update();

}

 

Regards,

Ram M

Hi Ram Mohan,

Hey I tried this option with a situation I have. I need to convert a string to a duration field. In the string I put a time to completion for Knowledge Articles, for example I place a 5 which mean 5 minutes and then I need to convert that in a GlideDuration field. How can I do it? 

 

Vishal Khandve
Kilo Sage

Hi,

try below code:

 

var dateString = "03/23/2017"; // Oct 23

var dateObject = new Date(dateString);

document.body.innerHTML = dateObject.toString();