---
schema_version: "1"
id: 5ca9663637db660e24e437a41a56190c7573b0d8009b18391e93dfacc4d9e451
title: toDateOrNull
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.6/dw-coercions-functions-todateornull.md
canonical_url: https://docs.mulesoft.com/dataweave/2.6/dw-coercions-functions-todateornull
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f44b63f2b696718790dbdaf72f257490721cf14084eca555947c67040412b960
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
---
product: DataWeave
version: 2.6
---

# toDateOrNull

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## toDateOrNull(str: String, formatters: Array<Formatter>): Date | Null

Transforms a `String` value into a `Date` value using the first `Formatter` that matches with the
given value to transform.

If none of the `Formatter` matches with the given value, the function returns a `null` value.

_Introduced in DataWeave version 2.5.0._

### Parameters

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p><code>str</code></p></td><td><p>String</p></td><td><p>The <code>String</code> value to transform into a <code>Date</code> value.</p></td></tr><tr><td><p><code>formatters</code></p></td><td><p>Array&lt;Formatter&gt;</p></td><td><p>The <code>array</code> of formatting to use on the <code>Date</code> value.</p></td></tr></tbody></table>

### Example

This example shows how `toDateOrNull` behaves with different inputs. It produces output in the
`application/dw` format.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Coercions
output application/dw
---
{
  a: toDateOrNull("2023-28-03", [{format: "yyyy/MM/dd"}, {format: "yyyy-dd-MM", locale: "en_US"}]),
  b: toDateOrNull("2023-28-03", [{format: "yyyy/MM/dd"}])
}
```

#### Output

```DataWeave
{
  a: |2023-03-28| as Date {format: "yyyy-dd-MM", locale: "en_US"},
  b: null
}
```
