Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Date time conversion (input format yyyy-MM-dd HH:mm:ss.SSSSS) in Mule 4

Getting the following error when trying to convert date time to a specific string format:

Cannot coerce String (2023-02-07 08:23:00.167000) to LocalDateTime, caused by: Text ‘2023-02-07 08:23:00.167000’ could not be parsed, unparsed text found at index 25

6| crtDate: dtTime as LocalDateTime {format : "yyyy-MM-dd HH:mm:ss.SSSSS"} as String {format:"yyyy-MM-dd’T’HH:mm:ss"}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
at main::main (line: 6, column: 12)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

%dw 2.0
var dtTime = '2023-02-07 08:23:00.167000'
output application/json
---
{
  crtDate: dtTime as LocalDateTime {format : "yyyy-MM-dd HH:mm:ss.SSSSS"} as String {format:"yyyy-MM-dd'T'HH:mm:ss"}  
}

Expected: 2023-02-07T08:23:00

>Solution :

The format string has 5 digits for the milliseconds however the input has 6 characters. Adding another S fixes it.

Example:

"yyyy-MM-dd HH:mm:ss.SSSSSS"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading