Need help with date/time field converting to string

Nowlearner
Kilo Guru

Hi,

I have the below script include, my start date field is date/time field.

With the below script, start date field output is being displayed as: MM - DD TIME - Year

For example: 08-05 00:00:00- 2018

i need the output as: 08-05-2018 00:00:00

var sc_include = function () {
var pencil = new cr_pencil();

return {
biglist: biglist,
type: 'sc_include'
};

function biglist(variables) {
var date = variables.start_date;

if (date) {
date = date.toString();

var day = date.split('-')[2];
var month = date.split('-')[1];
var year = date.split('-')[0];

if (variables.region == 'UK') {
date = [day, month, year].join('-');
} else {
date = [month, day, year].join('-');
}
}

return [{
condition: true,
label: '\n' + 'Start date: ',
value: date
}

]}

}

6 REPLIES 6

Sharique Azim
Mega Sage

Hi,

 

Maybe you can try this:

 

var date = variables.start_date;
var dt= new GlideDateTime(date);
gs.log(dt);
if (date) {
//date = date.toString();

var day = dt.getDayOfMonth;
var month = dt.getMonth;
var year = dt.getYear();
var str= '';
if (variables.region == 'UK') {
str= [day, month, year].join('-');
} else {
str= [month, day, year].join('-');
}
}

return str;

SanjivMeher
Kilo Patron
Kilo Patron

Please mark this thread closed my marking an answer correct if it resolved your issue


Please mark this response as correct or helpful if it assisted you with your question.