---
schema_version: "1"
id: fce059e4f9c13d5712ebfdb7ce36e57abf14d2b404ff76fb0cef64d856d4eae9
title: Parse Dates with DataWeave
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dataweave-cookbook-parse-dates.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-parse-dates
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ecc7df428d7bf7c530e4ae10a72aa5def650a0624286187f8ca5fdc3c2035526
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
keywords: studio, anypoint, transform, transformer, format, xml, json, metadata, dataweave, data weave, datamapper, dwl, dfl, dw, output structure, input structure, map, mapping
---

# Parse Dates with DataWeave

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

These DataWeave examples define a function (`fun`) in the DataWeave header to normalize date
separators (`/`, `.`, and `-`) within different date formats so that all of them use the same
separator (`-`).

The examples use these functions:

- `replace` so that all dates match a single pattern.

- `mapObject` to run through the `date` elements. The script applies the normalizing function to
  each `date`.

- `as` (in the second DataWeave script) to change the data type of the values to a Date type with a
  specific date format.

## Example: Returns Dates as String Types

DataWeave Script:

```dataweave
%dw 2.0
output application/xml
fun normalize(date) = (date) replace "/" with "-" replace "." with "-"
---
dates: (payload.dates mapObject {
    normalized_as_string: normalize($)
})
```

Input XML Payload:

```xml
<dates>
  <date>26-JUL-16</date>
  <date>27/JUL/16</date>
  <date>28.JUL.16</date>
</dates>
```

Output XML:

```xml
<?xml version='1.0' encoding='US-ASCII'?>
<dates>
  <normalized_as_string>26-JUL-16</normalized_as_string>
  <normalized_as_string>27-JUL-16</normalized_as_string>
  <normalized_as_string>28-JUL-16</normalized_as_string>
</dates>
```

## Example: Returns Dates as Date Types

DataWeave Script:

```dataweave
%dw 2.0
output application/xml
fun normalize(date) = (date) replace "/" with "-" replace "." with "-"
---
// Outputs date values as Date types in the specified format
dates: (payload.dates mapObject {
    normalized_as_date: (normalize($) as Date {format: "d-MMM-yy"})
})
```

Input XML Payload:

```xml
<dates>
  <date>26-JUL-16</date>
  <date>27/JUL/16</date>
  <date>28.JUL.16</date>
</dates>
```

Output XML:

```xml
<?xml version='1.0' encoding='UTF-8'?>
<dates>
  <normalized_as_date>2016-07-26</normalized_as_date>
  <normalized_as_date>2016-07-27</normalized_as_date>
  <normalized_as_date>2016-07-28</normalized_as_date>
</dates>
```

## Related Examples

- [Add and Subtract Dates](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-add-and-subtract-time)

- [Reference Multiple Inputs](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-reference-multiple-inputs)

## See Also

- [DataWeave Types](https://docs.mulesoft.com/dataweave/2.11/dataweave-types)

- [DataWeave Selectors](https://docs.mulesoft.com/dataweave/2.11/dataweave-selectors)

- [DataWeave Cookbook](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook)
