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

  • Home
  • SEARCH
  • 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 7048037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:50:36+00:00 2026-05-28T02:50:36+00:00

Im trying to get the Day / Month / Year from my datepicker. I

  • 0

Im trying to get the Day / Month / Year from my datepicker. I have the problem that the Month en the day never is correct. I give you the code below. The month is correct but it fails when the month is december. The day is never correct.

    public class myOnDateChangedListener implements OnDateChangedListener {

    public void onDateChanged(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        if (view.getId() == R.id.datePicker1) {
            startDay = view.getDayOfMonth();
            if(view.getMonth() == 11){
                startMonth = 12;
            }else{
            startMonth = (view.getMonth() + 1);
            }
            startYear = view.getYear();

        }
        if (view.getId() == R.id.datePicker2) {
            endDay = view.getDayOfMonth();
            if(view.getMonth() == 11){
                endMonth = 12;
            }else{
            endMonth = (view.getMonth() + 1);
            }

            endYear = view.getYear();

        }

    }

}
  • 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-05-28T02:50:36+00:00Added an answer on May 28, 2026 at 2:50 am

    Why do you use the view values, not the values passed in the method? Also no need for the special case of month == 11. Try this code (modified your own):

    public void onDateChanged(DatePicker view, int year, int monthOfYear,
                int dayOfMonth) {
            if (view.getId() == R.id.datePicker1) {
                startDay = dayOfMonth;
                startMonth = monthOfYear + 1;
                startYear = year;
            }
            if (view.getId() == R.id.datePicker2) {
                endDay = dayOfMonth;
                endMonth = monthOfYear + 1;
                endYear = year;
            }
    
        }
    

    EDIT: After reading your comment I feel the problem you get might be because of some other confusion on your side: I mean the fact that the Java Date class constructor that goes like this:

    public Date(int year, int month, int date)
    

    Initializes the date starting from 1st of January 1900th year. Warning: the month is between 0 and 11 and the day between 1 and 31. Take a look at the constructor. If you want to detect whether the problem is in the DatePicker itself or after that in the Java code try logging to narrow the scope of causes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get comfortable with jQuery and I have encountered some sample code that
I'm trying to get this Sinatra GET request to work: get '/:year/:month/:day/:slug' do end
I'm trying to get the four or five things that happened on this day
I have been trying all day to get some data properly formatted in a
Hey guys i have two date inputs containing three dropboxes for day,month and year
I'm trying to change this timestamp 2010-08-02 00:28:20 to month/day/year - 08/02/10 ..in the
I'm in the U.S., and we usually format dates as "month/day/year". I'm trying to
I'm getting a date from a string, parsing it to get the day, month
I am trying to get the lines count(entered) for Today, Month to date, year
So i'm just trying to print day month and year (not printing actually, i'll

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.