Reputation: 67
My input is a .csv
format file with a date of birth column which contains strings such as
Aug-03-2015
I want to change this coloumn to a date (if not possible then at least to another string) format as below
03-08-2015
. Tried the logic suggested by RyanCarter. I have now tried using
Birthday:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
where DOB is a string column in the .csv input. But i got the below exception.
Message : Exception while executing:
DOB:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
^
Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
Type : com.mulesoft.weave.mule.exception.WeaveExecutionException
Code : MULE_ERROR--2
********************************************************************************
Exception stack is:
1. Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
(com.mulesoft.weave.model.values.coercion.exception.UnsupportedTypeCoercionException)
com.mulesoft.weave.model.values.coercion.LocalDateTypeCoercionValue:30 (null)
2. Exception while executing:
DOB:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
^
Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0 (com.mulesoft.weave.mule.exception.WeaveExecutionException)
com.mulesoft.weave.mule.WeaveMessageProcessor$WeaveOutputHandler:166 (null)
********************************************************************************
Root Exception stack trace:
com.mulesoft.weave.model.values.coercion.exception.UnsupportedTypeCoercionException: Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
Upvotes: 0
Views: 3903
Reputation: 11606
Convert to a date firt using the date format, then back to a String using the second date format:
varOutput: 'Aug-03-2015' as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
Upvotes: 1