Hi,
I’m trying to convert a date from an XML file.
The current format is (dd/MM/yyyy) and I want to change the format to (yyyy/MM/dd)
I have made a script to do this.
var xmlDoc = new Document(job.getPath());
var orgdate = xmlDoc.evalToString("//root/row/Date");
// orgdate result is = 22/05/2019
var day = orgdate.split("/")[0];
// day result is = 22
var month = orgdate.split("/")[1];
// month result is = 05
var year = orgdate.split("/")[2];
// year result is = 2019
var date = new String (+year + "-" + +month + "-" + +day);
// date result is = 2019-5-22
The leading zero’s are now missing
Is there a way to keep the leading zero’s?
Thank you for your help.
Convert Date Format - Missing Leading Zero's
Re: Convert Date Format - Missing Leading Zero's
Hi,
Can you try to replace
var date = new String (+year + "-" + +month + "-" + +day);
with
var date = new String (year + "-" + month + "-" + day);
?
The extra plus signs make that Switch interprets the string as number and removes the leading zero's.
Can you try to replace
var date = new String (+year + "-" + +month + "-" + +day);
with
var date = new String (year + "-" + month + "-" + day);
?
The extra plus signs make that Switch interprets the string as number and removes the leading zero's.
Re: Convert Date Format - Missing Leading Zero's
Hi Padawan
Thank you very much - Yes that worked.
Regards
Thank you very much - Yes that worked.
Regards