---
schema_version: "1"
id: 0c26bdfafee417c4a7b76af88d5bb65b3c0fb8c7a809461947f0fa09647005a8
title: toTimeOrNull
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-coercions-functions-totimeornull.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-totimeornull
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 45f271e954b1432cc6d4125dc5ac629017ad8971431526cadc54ce215f8d98b0
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# toTimeOrNull

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

## toTimeOrNull(str: String, formatters: Array<Formatter>): Time | Null

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

### Example

This example shows how `toTimeOrNull` 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: toTimeOrNull("13:44:12.283-08:00", [{format: "HH:mm:ss.xxx"}, {format: "HH:mm:ss.nxxx"}]),
  b: toTimeOrNull("13:44:12.283-08:00", [{format: "HH:mm:ss.xxx"}])
}
```

#### Output

```DataWeave
{
  a: |13:44:12.000000283-08:00| as Time {format: "HH:mm:ss.nxxx"},
  b: null
}
```
