---
schema_version: "1"
id: 8021b1a4e6887ea842e55ed77b7ab547fa5f126ef3049701509f65fc85d78610
title: getYearsInDuration()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/ref-jsapi/ref-jsapi-auralocalizationservice-getyearsinduration.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/ref-jsapi-auralocalizationservice-getyearsinduration.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: b2d0a3907251e89154fd79ffbd86d4eb7c43637fb30cb6fded91034ea0cec319
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# getYearsInDuration()

Returns the number of years in a duration.

## Signature

`getYearsInDuration(Duration duration)`

## Parameters

**_duration_:** Type: `Duration`. The duration object returned by `$A.localizationService.duration`.

## Returns

**Type: `number`** The number of years in the duration.

## Sample Code

```javascript
var dur = $A.localizationService.duration(24, 'month');
// Returns 2
$A.localizationService.getYearsInDuration(dur);
```

**See Also**  


-   [duration()](https://developer.salesforce.com/docs/platform/aura-platform/guide/ref-jsapi-auralocalizationservice-duration.md)

