Search code examples
pentahokettlee4x

Changing date format in Pentaho using javascripting


I have an input excel sheet which has a field "fail_date". I want to change the format to dd.MM.yyyy HH:mm:ss. I am doing this in javascript shown below.

var temp = fail_date.getDate();
str2date(temp,"dd.MM.yyyy HH:mm:ss");

But I get the below error when i run

2015/05/07 17:48:01 - Modified Java Script Value 2 2 2.0 - ERROR (version 4.4.0-stable, build 17588 from 2012-11-21 16.02.21 by buildguy) : Could not apply the given format dd.MM.yyyy on the string for Thu Jan 01 11:05:50 IST 1970 : Format.parseObject(String) failed (script#5)

script#5 points to str2date(temp,"dd.MM.yyyy HH:mm:ss"); . Please help to solve this issue.


Solution

  • the variable temp is setted as date type object, but when you apply the str2date function, this function expects to be temp as string.

    So this is how your code should be:

    var temp = fail_date.getDate();
    temp = date2str(temp,"dd.MM.yyyy HH:mm:ss");
    

    remember now temp is a string type