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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:15:28+00:00 2026-05-24T19:15:28+00:00

I retrieve a Date from the database using the ResultSet rsExpid . Date joindate

  • 0

I retrieve a Date from the database using the ResultSet rsExpid.

Date joindate = rsExpid.getDate("join_date_ad");
System.out.println(joindate);
int year = joindate.getYear();
System.out.println(year);
int month =joindate.getMonth();
System.out.println(month);
int day = joindate.getDay();
System.out.println(day);
dateTimeJoin4.setDate(year, month, day);

When I print joindate to the console it shows correctly as 2011-08-03, but when I print the year to the console I was amazed to see 111. Similarly printing the month produced 7 and the day resulted in 3.

The variable dateTimeJoin4 is my SWT DateTime. It is not setting any value and it is also not giving any error message. Could please anybody help me on this?

  • 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-24T19:15:29+00:00Added an answer on May 24, 2026 at 7:15 pm

    Chances are you haven’t read the documentation for Date.getYear and Date.getMonth:

    Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

    and

    Returns a number representing the month that contains or begins with the instant in time represented by this Date object. The value returned is between 0 and 11, with the value 0 representing January.

    respectively. Likewise Date.getDay returns the day of the week, not the day of the month – you want Date.getDate() for that (or preferrably a different API entirely, either Calendar or Joda Time).

    This has nothing to do with SWT’s DateTime type – after all, you only use that in the last line. When something behaves unusually, your first port of call should be the documentation. SWT’s DateTime.setDate method is documented to require a year between 1752 and 9999, so 111 will be confusing it. Admittedly it would have been nice if it had thrown an exception, but even so…

    The fact that you’re calling deprecated methods should have been a hint to you, although Calendar also uses 0-11 for its months.

    Personally I would strongly encourage you to use Joda Time for as much of your date and time work as you can. It’s a far superior date and time API to the one built into Java. It’s not immediately clear whether it’s worth you using it here (if this is all you have to do) but if you’re doing anything at all significant (including parsing, formatting or any kind of arithmetic) you should be using it.

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

Sidebar

Related Questions

hey, I'm wondering how to retrieve data from my database using php to get
I am currently using NSURLConnection to download some date from a database through a
I have a date time in the database and I retrieve it from the
I'm using MySQL Connector to retrieve data from a mySQL database to a .NET
How do I retrieve a date from SQL Server in YYYY-MM-DD format? I need
I need to retrieve the date from a UIDatePicker (Preferably I would also like
I want to retrieve the moth from a date(in textbox),then If that retrieved month
I'm trying to retrieve records from table by knowing the date in column contains
Is there a managed API to retrieve an application's install date using the Product
Is there a way to, given a date, retrieve the season of the year?

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.