Forums

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

ScriptRunner - get dates between two dates

Gleb Kartashov
Contributor
September 25, 2020

Hi! I need to find dates (not days!) between two given dates. This is used in workLog created custom Listener

E.g.

start date = Sep 20

end date = Sep 25

result = Sep 20, Sep 21, Sep 22, Sep 23, Sep 24, Sep 25

Found this article but it show days between and I need dates

Thanks in advance!

2 answers

0 votes
Steven
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!
May 22, 2021

You can try this code:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@NonCPS
def daterange(ds,de) {
def lst = []
SimpleDateFormat parser = new SimpleDateFormat("yyyy.MM.dd")
Date d1 = parser.parse(ds)
Date d2 = parser.parse(de)
d1.upto(d2) {
lst.add(it.format("yyyy.MM.dd"))
}
return lst
}
0 votes
Jeroen Poismans
Community Champion
October 8, 2020

Hi Gleb,

You may find this article interesting. Its is a Java resource but the Java7 example can easily be refactored to Groovy with minor adjustments:

https://www.baeldung.com/java-between-dates 

 

Let me know if this helped!

Regards,

Jeroen

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events