Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:35:29+00:00 2026-06-07T05:35:29+00:00

How to get all dates between two dates in Android. For example. I have

  • 0

How to get all dates between two dates in Android.

For example. I have two Strings.

String first="2012-07-15";  
String second="2012-07-21"; 

I convert and get dates from these strings.

DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");                                    
DateFormat df2 = new SimpleDateFormat("MMM dd");
String mydate = df2.format(df1.parse(first));

This way I get both dates from first and second String.

Now I also display all dates between these two dates.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:35:31+00:00Added an answer on June 7, 2026 at 5:35 am

    it is better not to use any hardcoded values in date calculations. we can rely on java Calendar class methods to do this task

    see the code

    private static List<Date> getDates(String dateString1, String dateString2)
    {
        ArrayList<Date> dates = new ArrayList<Date>();
        DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
    
        Date date1 = null;
        Date date2 = null;
    
        try {
            date1 = df1 .parse(dateString1);
            date2 = df1 .parse(dateString2);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);
    
    
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);
    
        while(!cal1.after(cal2))
        {
            dates.add(cal1.getTime());
            cal1.add(Calendar.DATE, 1);
        }
        return dates;
    }
    

    and use it as below

        List<Date> dates = getDates("2012-02-01", "2012-03-01");
        for(Date date:dates)
            System.out.println(date);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get all rows from a table that lie between two dates.
I am trying to get all logfiles between two dates with regular expressions. My
I have two DateTime s, and I want to get all DateTime s between
how to get all products between two dates like last month products, this month
I am generating all dates between two dates. public List<Date> generateRangeDates(Date firstDate, Date lastDate)
How can I get the number of weekdays between two given dates without just
I have a REST URL to get all users formatted like this: http://example.com/users To
How can I echo all dates for mondays/ wednesday / friday between these two
Sorry for my english. I have a two dates(DateTime): latest_client = Client.objects.all().latest('id').ordered_at first_client =
I'm trying to get my linq statement to get me all records between two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.