Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner - get dates between two dates

Edited

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 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
}

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
Community showcase
Published in Jira Service Management

Submit your Jira Service Management use case and win!

Hi everyone - in case you haven’t heard, we’re hosting the show of the century on November 10th: High Velocity: ITSM World Tour.     This virtual, concert-themed experience...

271 views 1 9
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you