DataWeave Parsing Date Modes: SMART, STRICT, and LENIENT
We know that in DataWeave the types can be coerced from one type to another. For that we use the as operator.
There is a limited list of type coercion that you can see here:
https://docs.mulesoft.com/mule-runtime/4.3/dataweave-types-coercion
For example, you can coerce a String or Number to a DateTime or a Number or Boolean to a String. Depends on your use case.
There is a property called mode that we can use when we are parsing date and time values. The mode parameter has three different valid values:
SMART
STRICT
LENIENT
SMART (default) mode
The default mode when you are parsing dates is SMART. So you’ll have the same result if you explicitly use the mode parameter as SMART or not.
Let’s say we need to parse the following date in ‘MM-dd-yyyy’ format: 02-31-2020.
As you can notice, this is an invalid date (take a quick look at your calendar), February 2020 had only 29 days.

Let’s try to parse that date using the default mode (no explicit mode parameter in your DataWeave script).
Here is the input:
%dw 2.0
output application/json
var badDate = '02-31-2020' //notice that this date doesn't exist
var dateFormat = 'MM-dd-yyyy'
---
{
defaultDate: badDate as Date {format: dateFormat}
}
This is the output:
{
"defaultDate": "02-29-2020"
}
Did you notice that the default mode autocorrected the date value? It results in a valid date two days before the input date: 02-29-2020.
Now, let’s use the SMART mode explicitly as follows:
%dw 2.0
output application/json
var badDate = '02-31-2020' //notice that this date doesn't exist
var dateFormat = 'MM-dd-yyyy'
---
{
smartDate: badDate as Date {mode: "SMART", format: dateFormat}
}
Here is the SMART output:
{
"smartDate": "02-29-2020"
}
As you can see, you will have the same result using both: the DEFAULT mode and the SMART mode.
LENIENT mode
We might think that the LENIENT mode, being tolerant, would also correct the date to a valid day on the calendar. However, the result is different from the default mode.
Let's do a test using the LENIENT mode as follows:
%dw 2.0
output application/json
var badDate = '02-31-2020' //notice that this date doesn't exist
var dateFormat = 'MM-dd-yyyy'
---
{
lenientDate: badDate as Date {mode: "LENIENT", format: dateFormat}
}
The result is:
{
"lenientDate": "03-02-2020"
}
Did you notice that this mode gives us a valid date as well? But in this case it gives us a date two days after the input date: 03-02-2020.
Why two days and not only one? That’s because February 2020 had only 28 days as we saw in our calendar and we are trying Feb 31, 2020. So, Feb 30, 2020 does not exist, Feb 31, 2020 does not exist either. There are two invalid days (not only one) between the last valid date (Feb 29, 2020) and the (invalid) input