# I need to write a function

**URL:** <https://forums.pega.com/t/i-need-to-write-a-function/7564>\
**Category:** User Experience\
**Tags:** business-simulations, other-industry, user-experience, solutions-engineer, case-management, pega-platform\
**Created:** [June 25, 2024, 1:10pm UTC](https://forums.pega.com/t/i-need-to-write-a-function/7564 "2024-06-25T13:10:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SumanthI17001889](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@SumanthI17001889](https://forums.pega.com/u/SumanthI17001889)\
**Post date:** [June 25, 2024, 1:10pm UTC](https://forums.pega.com/t/i-need-to-write-a-function/7564/1 "2024-06-25T13:10:31Z")

</div>

I need to write a function -Add 2 years from any present given month for example - 2022-05-17 (yyyy-MM-day) and answer should be-2024-05-17

---

<div class="post-metadata">

**Author:** ![Mamatha\_Adiraju](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/mamatha_adiraju/32/15471_2.png) [@Mamatha\_Adiraju](https://forums.pega.com/u/Mamatha_Adiraju)\
**Post date:** [June 25, 2024, 2:02pm UTC](https://forums.pega.com/t/i-need-to-write-a-function/7564/2 "2024-06-25T14:02:16Z")

</div>

Hi @SumanthI17001889

You can this below function

**FormatDateTime(addCalendar(getCurrentDateStamp(),‘2’,“”,“”,“”,“”,“”,“”),“yyyy-MM-dd”,“”,“”)**

Note: addCalendar function is the actual function to add the year and FormatDateTime is used to convert date into required date format.

Regards

Mamatha

 ![AddYearToDateFunction.png](https://pega1.discourse-cdn.com/pega/original/2X/4/471c09471d9cc01130b10b972f3cfc902dcb6843.png)

---

<div class="post-metadata">

**Author:** ![Akhila\_Chamakura](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Akhila\_Chamakura](https://forums.pega.com/u/Akhila_Chamakura)\
**Post date:** [June 26, 2024, 5:12am UTC](https://forums.pega.com/t/i-need-to-write-a-function/7564/3 "2024-06-26T05:12:54Z")

</div>

Hi @SumanthI17001889,

To add 2 years to a given date in Pega, use the @addToDate() function.  
**@(Pega function) : AddToDate(“2022-05-17”, 2, “years”)**

Where “2” indicates the number of years to add.

Thanks.
