Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.Date issue

 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an issue that I cannot understand. Today is the 24th of June, 2011. Here is my code:



as expected, both DAY_OF_MONTH and DATE return the same integer. However, it returns the WRONG integer. It returns 5??? I do not understand this at all. Any ideas?

I post this here as I am about to create an SQL date, but I guess I am still in the wrong section. I dont know where else to post it.

Thanks

Greg
 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the API.. use the get and set

DAY_OF_MONTH

public static final int DAY_OF_MONTH

Field number for get and set indicating the day of the month. This is a synonym for DATE. The first day of the month has value 1.


Checking the source code i found this

public final static int DAY_OF_MONTH = 5;

http://www.docjar.com/html/api/java/util/Calendar.java.html

you are accessing Calendars static DAY_OF_MONTH instead of your objects DAY_OF_MONTH, which gets created using Calendar.getInstance();

 
Paul Clapham
Sheriff
Posts: 21567
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are seeing isn't something from your Calendar object. It's a static variable Calendar.DATE which is an arbitrary constant which you use to say "Gimme the day of the month"... like this...


(By the way, why is this a question about java.sql.Date?)
 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That seems to work now! Thank you, very much. I posted this question here because my end goal is an sql.Date which the user is selecting that I am putting into an SQLite3 database. I just did not know any better place to post it. Thank, very much.
 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
( if I posted the rest of the code, it would show me making the sql date, but you are correct, this should have been called Calendar issue)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic