---
schema_version: "1"
id: 1e4845da0770a814210de04b65e860342429de5f2cd42b8424688868ec95d2f1
title: years
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-periods-functions-years.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-periods-functions-years
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e338fda0da7930eb593736e4c2094a81e8a4d89f61f896ecc1ee5bbd982e4d29
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# years

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

## years(nYears: Number): Period

Creates a Period value from the provided number of years.

The function applies the `period` function to the input value.

_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>nYears</code></p></td><td><p>A whole number for the number of years. A positive or negative number is valid.</p></td></tr></tbody></table>

### Example

This example shows how `years` behaves with different inputs. It adds a year to a DateTime value,
and it converts the whole number 4 into a number of years in the Period format (`P4Y`). Notice that
`years(-1) + years(2)` returns the number of months.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Periods
output application/json
---
{
  nextYear: |2020-10-05T20:22:34.385Z| + years(1),
  fourYearPeriod: years(4),
  addNegativeValue: years(-1) + years(2)
}
```

#### Output

```Json
{
   "nextYear": "2021-10-05T20:22:34.385Z",
   "fourYearPeriod": "P4Y",
   "addNegativeValue": 12
}
```
