javascriptpentahokettledate-conversionpentaho-spoon

Date format conversion from "yyyy-mm-dd" to "dd/mm/yyyy" in pentaho using javascript


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

This is the error I got after using select value step


Solution

  • 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");