Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Hello community

Andres Martinez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 10, 2018

I am working on a project and I want to create a script field to calculate the days elapsed up to the current date.

 

class Ejemplo {

public static void main(String[] args) {
def lastWeek = new Date() - 7;
def today = new Date()

println daysBetween(lastWeek, today)
}

static def daysBetween(def startDate, def currentDate) {

use(groovy.time.TimeCategory) {
def duration = currentDate - startDate
println "days: ${duration.days}"

return duration.days
}
}
}

 I have advanced up here but I find myself stuck, I appreciate any help

 

1 answer

0 votes
Leo
Community Champion
December 10, 2018

Hi @Andres Martinez,

If you are trying to find the days of the issue b/w created and today you can use the below script in script field  :)

import org.joda.time.Days
import org.joda.time.LocalDate

int days = Days.daysBetween(LocalDate.fromDateFields(issue.getCreated()), LocalDate.fromDateFields(new Date())).getDays()

 

Regards,

Leo 

Suggest an answer

Log in or Sign up to answer