%dw 2.0
import * from dw::util::Coercions
import * from dw::Runtime
output application/dw
---
{
a: toDate("2023-28-03", [{format: "yyyy/MM/dd"}, {format: "yyyy-dd-MM", locale: "en_US"}]),
b: try(() -> toDate("2023-28-03", [{format: "yyyy/MM/dd"}])).error.message
}
toDate
toDate(str: String, formatters: Array<Formatter>): Date
Transforms a String
value into a Date
value using the first Formatter
that
matches with the given value to transform.
Introduced in DataWeave version 2.5.0.
Parameters
Name | Type | Description |
---|---|---|
|
String |
The |
|
Array<Formatter> |
The |
Example
This example shows how toDate
behaves with different inputs.
It produces output in the application/dw
format.
toDate(str: String, format: String | Null = null, locale: String | Null = null): Date
Transforms a String
value into a Date
value
and accepts a format and locale.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The |
|
The formatting to use on the |
|
Optional ISO 3166 country code to use, such as |