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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

222 views 0 6
Read article

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