Search code examples
muledatetime-formatdataweavemysql-date

convert MYSQL date time format to UTC time format in Mule 4


I have a requirement where I need to format the dateTime value received from MySql db to UTC time in using Mule 4 Dataweave. Example: i/p: 2021-01-20 00:00:00.0 expected o/p: 2021-01-20T00:00:00.000Z.


Solution

  • What you receive from the Mulesoft Database connector is a Java SQL Date object, not a String, unless the query formats it on the DB. If you want a string representation of it, you need to format it using something like this:

    myDate as String {format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"}