# Need to add 2 years to ISO Timestamp to be used in request

**URL:** <https://community.postman.com/t/need-to-add-2-years-to-iso-timestamp-to-be-used-in-request/56050>\
**Category:** Help Hub\
**Tags:** request-body\
**Created:** [December 29, 2023, 2:19pm UTC](https://community.postman.com/t/need-to-add-2-years-to-iso-timestamp-to-be-used-in-request/56050 "2023-12-29T14:19:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adinduik](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/adinduik/32/26963_2.png) [@adinduik](https://community.postman.com/u/adinduik)\
**Post date:** [December 29, 2023, 2:19pm UTC](https://community.postman.com/t/need-to-add-2-years-to-iso-timestamp-to-be-used-in-request/56050/1 "2023-12-29T14:19:33Z")

</div>

I need to be able to add two years to my iso timestamp for my request body

I have this in my pre-request script

pm.collectionVariables.set(“timestamp”, pm.variables.replaceIn(‘{{$isoTimestamp}}’));

I need the timestamp in the future for an expiry date

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [January 5, 2024, 4:11pm UTC](https://community.postman.com/t/need-to-add-2-years-to-iso-timestamp-to-be-used-in-request/56050/2 "2024-01-05T16:11:01Z")

</div>

The following seems to work.

```auto
let timeStamp = pm.variables.replaceIn("{{$isoTimestamp}}");
console.log(timeStamp);

let twoYearsFromNow = new Date(new Date(pm.variables.replaceIn("{{$isoTimestamp}}")).setFullYear(new Date().getFullYear() + 2)).toISOString();
console.log(twoYearsFromNow);

```

![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/8/28f2c054dfb9f446138de0a500d3c977f250e33e.png)

Cribbed from [javascript - Add A Year To Today’s Date - Stack Overflow](https://stackoverflow.com/questions/33070428/add-a-year-to-todays-date)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [February 4, 2024, 4:11pm UTC](https://community.postman.com/t/need-to-add-2-years-to-iso-timestamp-to-be-used-in-request/56050/3 "2024-02-04T16:11:10Z")

</div>

Closed on February 4, 2024, 4:11pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
