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 7843541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:34:25+00:00 2026-06-02T16:34:25+00:00

I am trying to do calculate days between 2 dates as follow: Obtain current

  • 0

I am trying to do calculate days between 2 dates as follow:

  1. Obtain current date
  2. Obtain past OR future date
  3. Calculate the difference between no. 1 and no. 2
  4. Present the dates in the following format
    • If the result is in past (2 day ago) or in the future (in 2 days)
    • Format will: days, weeks, months, years

I tried different ways but couldn’t get the result I wanted above. I found out that Android DatePicker dialog box convert date into Integer. I have not found a way to make DatePicket widget to return date variables instead of integer.

private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, **int** year, 
                                  **int** monthOfYear, **int** dayOfMonth) {
                enteredYear = year;
                enteredMonth = monthOfYear;
                enteredDay = dayOfMonth;
            }
        };

I tried to convert the system date to Integer, based on the above, but this doesn’t really work when trying to calculate days between 2 dates.

private void getSystemDate(){
     final Calendar c = Calendar.getInstance();

        mYear = c.get(Calendar.YEAR);
        systemYear = mYear;

        mMonth = c.get(Calendar.MONTH);
        systemMonth = mMonth + 1;

        mDay = c.get(Calendar.DAY_OF_MONTH);
        systemDay = mDay;

}
  • 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-02T16:34:26+00:00Added an answer on June 2, 2026 at 4:34 pm
    /** 
      *  Returns a string that describes the number of days
      *  between dateOne and dateTwo.  
      *
      */ 
    
    public String getDateDiffString(Date dateOne, Date dateTwo)
    {
        long timeOne = dateOne.getTime();
        long timeTwo = dateTwo.getTime();
        long oneDay = 1000 * 60 * 60 * 24;
        long delta = (timeTwo - timeOne) / oneDay;
    
        if (delta > 0) {
            return "dateTwo is " + delta + " days after dateOne";
        }
        else {
            delta *= -1;
            return "dateTwo is " + delta + " days before dateOne";
        }
    }
    

    Edit: Just saw the same question in another thread:
    how to calculate difference between two dates using java

    Edit2: To get Year/Month/Week, do something like this:

    int year = delta / 365;
    int rest = delta % 365;
    int month = rest / 30;
    rest = rest % 30;
    int weeks = rest / 7;
    int days = rest % 7;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to calculate the difference between 2 dates, the current date and the
I am trying to calculate the difference between two dates. This is what I'm
I am trying to calculate daysbetween difference between two dates in the grid. This
I am trying to calculate the number of days between two dates like this:
I'm trying to calculate TimeSpans between dates. I have no problem with this if
I'm trying to calculate the number of days between two days, but I'm running
I am trying to calculate an interval between now and a user defined date
I'm trying to do 2 things. Calculate number of business days to date in
I am trying to calculate the days on Blur method of End Date. But
i'm trying to use the class DateTime (php>=5.3) to calculate difference from 2 date.

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.