%dw 2.0
output application/json
---
payload.message as String as Date {"format":"MMddyyyy" } default null
for Feb month which is not leap year the input is:
{
"message": "02291947"
}
Output is:
"02281947"
Cannot coerce String (02321947) to Date, caused by: Text '02321947' could not be parsed: Invalid value for DayOfMonth (valid values 1 - 28/31): 32
4| payload.message as String as Date {"format":"MMddyyyy" }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
at main::main (line: 4, column: 1)
%dw 2.0
output application/json
fun validDate(d) = if (d == d as Date {format: "MMddyyyy"} as String {format: "MMddyyyy"} ) d else null
---
{
noLeap: validDate('02292019'),
valid: validDate('02282019'),
invalid: validDate('04312019')
}
001122447

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.