I have a string which has a date in this format: n_date=2014-04-20
I want to convert it into date data type
var Final_date = str2date(n_date,"yyyy-MM-dd");
but I get an error.
I'm do this in pentaho
You don't need a Java script step to do that. It's much easier and faster to use a calculator step or a select values step instead:
1) Calculator step: Create a new field, Final_date as a Copy of field A; on Field A put the name of your input string; Data type is date and on Conversion mask choose the yyyy-MM-dd format (you don't have to pick one from the dropdown menu, you can write your own);
2) Select values: on the Metadata panel, choose your input field and Date as the data type; as above, fill in the date format your data comes in.
The difference between 1) and 2) is that in the 1st case you get a new field of the Date type, whereas in the 2nd case you change the data type of the input field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With