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!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.