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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:35:17+00:00 2026-06-11T10:35:17+00:00

I am developing android application, in that application How to calculate the end date

  • 0

I am developing android application, in that application How to calculate the end date based on Start Date and No of days?E.g I have starting date Sep 13, 2012 if i add 45 days with that date I will get 27 October 2012.

How to do that?

I cannot use the date function inside if statement.

My code:

f (resCrop.equals(“Paddy”))
{

    if(rescultivation1.equals("Conventional method - Delta"))
        {
            if(resvariety1.equals("Short duration"))
            {
                WA.setVisibility(View.VISIBLE);
                TONE.setVisibility(View.VISIBLE);
                TTWO.setVisibility(View.VISIBLE);
                TTHREE.setVisibility(View.VISIBLE);
                //date calculation
                        SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy");
                Calendar c1 = Calendar.getInstance(); // Get Calendar Instance
            try {
                c1.setTime(sdf.parse(resDate));
                } catch (ParseException e) 
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                c1.add(Calendar.DATE, 3);  // add 3 days
                sdf = new SimpleDateFormat("dd-M-yyyy");

          Date resultdate = new Date(c1.getTimeInMillis());   // Get new time 
          String dateInString = sdf.format(resultdate);
          WP.setText(dateInString);
          WP.setEnabled(false);
          Calendar c2 = Calendar.getInstance();
          c2.add(Calendar.DATE, 35);  // add 45 days
          sdf = new SimpleDateFormat("dd-M-yyyy");
            }
        }
     }

Its not working inside the if statement. if i used outside if its working fine. how to resolve this problem. please advice me.

  • 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-11T10:35:19+00:00Added an answer on June 11, 2026 at 10:35 am

    Try this code . You can use any date format what you want.

        String dateInString = "2011-09-13";  // Start date
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    
        Calendar c = Calendar.getInstance(); // Get Calendar Instance
        c.setTime(sdf.parse(dateInString));
    
        c.add(Calendar.DATE, 45);  // add 45 days
        sdf = new SimpleDateFormat("MM/dd/yyyy");
    
        Date resultdate = new Date(c.getTimeInMillis());   // Get new time 
        dateInString = sdf.format(resultdate);
        System.out.println("String date:"+dateInString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an Android application that would have an offline data in start
I'm developing a simple Android application that would have an action bar on the
Hi an developing drawing android application. in that i want to add a sticker(image)
I have an android application that I'm developing, and the application really just a
i have developing an android application that requests an httpget and then it converts
I am developing an Android application that uses a WebView pointed at a jQueryMobile-based
I'm developing android application.In that i want to pick a date and time in
I'm developing an Android application that uses native code. I need to add an
I'm developing an Android application that has many activities. I have a Logout Activity
Hi i am developing android application. I that i have creating the dynamic table

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.