I am trying to format a string date yyyymmdd into a date field 'mm-dd-yyyy' to update a date filed on a table. Here is the code i am trying to use
This is inserting wrong date something like this "04-12-0011". So I am trying to figure out on how to format this date. Any directions or guidance is greatly appreciated.
Code:
var g = new GlideRecord('table1);
g.query();
var newDate = g.getValue('end_date'); //end_date string comes as //yyyyMMDD (20200219)
var year1 = newDate.substr(0,4);
var month1 = newDate.substr(4,2);
var date1 = newDate.substr(6,2);
var newDate = month1 + "-" + date1 + "-" + year1;
gs.log(newDate);//The date is showing as expected ('02-19-2020')
gs.log(date2);
g.setValue('expiration_date',newDate);
g.update();
This is inserting wrong date something like this "04-12-0011". So I am trying to figure out on how to format this date. Any directions or guidance is greatly appreciated.