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

# toLocalDateTimeOrNull

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

## toLocalDateTimeOrNull(str: String, formatters: Array<Formatter>): LocalDateTime | Null

Transforms a `String` value into a `LocalDateTime` 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>LocalDateTime</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>LocalDateTime</code> value.</p></td></tr></tbody></table>

### Example

This example shows how `toLocalDateTimeOrNull` 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: toLocalDateTimeOrNull("2003-10-01 23:57:59", [{format: "uuuu/MM/dd HH:mm:ss"}, {format: "uuuu-MM-dd HH:mm:ss"}]),
  b: toLocalDateTimeOrNull("2003-10-01 23:57:59", [{format: "uuuu/MM/dd HH:mm:ss"}])
}
```

#### Output

```DataWeave
{
  a: |2003-10-01T23:57:59| as LocalDateTime {format: "uuuu-MM-dd HH:mm:ss"},
  b: null
}
```
