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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:03:51+00:00 2026-06-04T19:03:51+00:00

I am trying to take 3 separate integer inputs (year,month,day) and taking these 3

  • 0

I am trying to take 3 separate integer inputs (year,month,day) and taking these 3 entries and forming an object of date from them so I can use it to compare other dates.

This is what I have so far, at a loss at where to go from here:

public void compareDates() {

    String dayString = txtOrderDateDay.getText();
    String monthString = txtOrderDateMonth.getText();
    String yearString = txtOrderDateYear.getText();

    int day = Integer.parseInt(dayString);
    int month = Integer.parseInt(monthString);
    int year = Integer.parseInt(yearString);
}

Many thanks for any help you have to offer.

  • 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-04T19:03:53+00:00Added an answer on June 4, 2026 at 7:03 pm

    Try this, noticing that months start in zero so we need to subtract one to correctly specify a month:

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month-1);
    calendar.set(Calendar.DATE, day);
    Date date = calendar.getTime();
    

    Or this:

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month-1, day);
    Date date = calendar.getTime();
    

    Or this:

    Date date = new GregorianCalendar(year, month-1, day).getTime();
    

    The first method gives you more control, as it allows you to set other fields in the date, for instance: DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, WEEK_OF_MONTH, WEEK_OF_YEAR, MILLISECOND, MINUTE, HOUR, HOUR_OF_DAY etc.

    Finally, for correctly formatting the date as indicated in the comments, do this:

    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    String strDate = df.format(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 take a look at IE's DOM from a separate thread that
I am trying to take information from a <tr> and prefill it in all
I'm trying to take an existing JSON object and create smaller JSON chunks out
I was trying to separate my DAL from my Business Layer, and in doing
I am trying to take tables from one Access Database File, add them to
I’m trying to make something that will take lines of input from the user,
I'm trying to separate the hours, minutes, seconds, and milliseconds from an inputed time.
I am trying to take a variable from $_POST , run mysql_real_escape_string and a
I'm trying to take values from a table and put them into a string
I'm trying to digitally read all separate 8 sensors from a QTRA 8-sensor board:

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.