Reputation: 840
I have a csv file where the date field has a format "yyyy-mm-dd" and I wish to convert it into "dd/mm/yyyy" using javascript. This is the javascript it found out from this reference
"could not apply the given format yyyy/mm/dd on the string for 2015-02-04 :Format.parseObject(String) failed(script#3)"
this is the javascript code I used
var dateObj = str2date(Date_of_joining, "yyyy/mm/dd");
var newDate = date2str(dateObj, "dd/MM/yyyy");
I even tried using Select Value step and changed the meta data to date and specified the format to "dd/MM/yyyy" but still not working.How do I solve this
Upvotes: 1
Views: 9771
Reputation: 703
function convertLinuxDate(linux_date) {
//linux_date = "2001-01-02"
var arrDate = linux_date.split("-");
return arrDate[1] + "/" +arrDate[2] + "/" + arrDate[0];
}
//returns 01/02/2001
Upvotes: 4
Reputation: 2020
Here we go:
Try to reconstruct DateTime string as like this:
var dateObj = new Date(Date_of_joining);
var newDate = new Date(dateObj );
var formattedString = [newDate.Date(),newDate.Month()+1, newDate.getFullYear()].join("/");
alert(formattedString );
Hope it helps;)
Upvotes: 1
Reputation: 79
The date you are parsing is not using slashes, but you're defining slashes when you parse it. Switch your slashes to dashes:
var dateObj = str2date(Date_of_joining, "yyyy-mm-dd");
var newDate = date2str(dateObj, "dd/MM/yyyy");
Upvotes: 5