---
schema_version: "1"
id: d3c301e3e771da7f6b692a510f9caf0b309c283dcf94f80e87e0c221fe218913
title: toDate
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dw-coercions-functions-todate.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dw-coercions-functions-todate
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 8cc75347b4d6990b1a2ad720bb9003a8f3e8981f248e23833332c730c0b57901
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
---

# toDate

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

## 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

<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 `toDate` behaves with different inputs. It produces output in the
`application/dw` format.

#### Source

```DataWeave
%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
}
```

#### Output

```DataWeave
{
  a: |2023-03-28| as Date {format: "yyyy-dd-MM", locale: "en_US"},
  b: "Could not find a valid formatter for '2023-28-03'"
}
```

## 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

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>str</code></p></td><td><p>The <code>String</code> value to transform into a <code>Date</code> value.</p></td></tr><tr><td><p><code>format</code></p></td><td><p>The formatting to use on the <code>Date</code> value. A <code>null</code> value has no effect on the <code>Date</code> value. This parameter accepts Java character patterns based on ISO-8601. A <code>Date</code> value, such as <code>2011-12-03</code>, has the format <code>uuuu-MM-dd</code>.</p></td></tr><tr><td><p><code>locale</code></p></td><td><p>Optional ISO 3166 country code to use, such as <code>US</code>, <code>AR</code>, or <code>ES</code>. A <code>null</code> or absent value uses your JVM default.</p></td></tr></tbody></table>

### Example

This example shows how `toDate` 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: toDate("2015-10-01"),
  b: toDate("2003/10/01","uuuu/MM/dd")
}
```

#### Output

```DataWeave
{
  a: |2015-10-01|,
  b: |2003-10-01| as Date {format: "uuuu/MM/dd"}
}
```
