Subtract months to a date custom field and populate another date field from the result

Hi, 

the requirement is to subtract months from a date a custom field and put the result in another date custom field. 

example

Datefield2 = Datefield1 - 10 months

I could subtract days only using script runner, any ideas?

Thanks, 

Flan

1 answer

Hi Flan,

If you want the result in a scripted field then the script will br something like 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def months = 3
def dateACF = customFieldManager.getCustomFieldObjectByName("First DateTime")
def dateAValue = issue.getCustomFieldValue(dateACF) as Date

def dateB = Calendar.getInstance()

dateB.setTime(dateAValue)
dateB.add(Calendar.MONTH, -months)
dateB.getTime()

with

Searcher: Date Time Range picker
Template: Date Time Picker

Suggest an answer

Log in or Sign up to answer
Community showcase
Asked Thursday in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

4,654 views 20 14
View question

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you