Fetch list of in-between dates using Java

0 votes

I have two dates(start and end date), but I want to fetch the list of all the dates lying between the start and the end date using Java. Can someone guide me, how to perform this?

May 10, 2018 in Java by v.liyyah
• 1,300 points

2 answers to this question.

0 votes

I tried generating the list of the in-between dates using Joda-Time. Check out the below code:

int myDates = Days.daysBetween(startDate, endDate).getDays();
List<LocalDate> dates = new ArrayList<LocalDate>(myDates);  // Set initial capacity to `days`.
for (int i=0; i < myDates; i++) {
    LocalDate dt = startDate.withFieldAdded(DurationFieldType.days(), i);

Hope this helps!

answered May 10, 2018 by geek.erkami
• 2,680 points
0 votes

java.time Package

The new java.time.package in Java 8 incorporates the features of the Joda-Time API.

You could probably try this code snippet:

String sd = "2019-08-01";
String ed = "2019-08-30";
LocalDate start = LocalDate.parse(sd);
LocalDate end = LocalDate.parse(ed);
List<LocalDate> totalDates = new ArrayList<>();
while (!start.isAfter(end)) {
               start = start.plusDays(1);
answered Aug 21, 2019 by Sirajul
• 59,090 points

Related Questions In Java

0 votes
2 answers

I want list of date of every week based on pass dynamically "Mon ,Tue, Wed, Thu, Fri, Sat, Sun" between startDate and endDate using Java 8 LocaleDate

public List<LocalDate> getWeeklyDateByStringofDays(String daysOfWeek, LocalDate startDate, ...READ MORE

answered Sep 14, 2020 in Java by anonymous
• 190 points
0 votes
2 answers

What is the difference between Set and List in java?

LIST SET Duplicates YES NO Order Ordered Depends on Implementation Positional Access YES NO List is an ordered sequence ...READ MORE

answered Aug 14, 2019 in Java by Sirajul
• 59,090 points
0 votes
2 answers

How can I sort values of a Map in Java using its key

Assuming TreeMap is not good for you ...READ MORE

answered Oct 10, 2018 in Java by Sushmita
• 6,900 points
0 votes
2 answers

What is the difference between Type List and type ArrayList in Java

By List, you actually tell, that your object ...READ MORE

answered Aug 28, 2019 in Java by Sirajul
• 59,090 points
0 votes
3 answers

Increment the date in Java by 1-day

import java.time.LocalDate; public class DateIncrementer { static ...READ MORE

answered Aug 1, 2018 in Java by Akrati
• 3,170 points
0 votes
1 answer

How to calculate the difference between two date instances in Java?

You can use Joda Time Library. Interval i ...READ MORE

answered May 4, 2018 in Java by Parth
• 4,630 points
0 votes
1 answer

Convert Milliseconds to “X mins, x seconds” in Java?

I wrote a function which converts milliseconds ...READ MORE

answered May 30, 2018 in Java by Rishabh
• 3,620 points
0 votes
1 answer

How can I get the current date and time in UTC or GMT in Java?

This definitely returns UTC time: as String ...READ MORE

answered Jun 7, 2018 in Java by Rishabh
• 3,620 points
0 votes
1 answer

Working of post increment operator in Java

Well, I think the confusion is because ...READ MORE

answered May 23, 2018 in Java by geek.erkami
• 2,680 points
+2 votes
3 answers

Listing all the subclasses of a specific class in Java

Try with BurningWave core library. Here an ...READ MORE

answered Dec 29, 2019 in Java by anonymous
• 460 points

edited Jan 9, 2020 by anonymous 5,640 views