Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and the fly likes java.sql.Date to java.util.Calendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.Date to java.util.Calendar" Watch "java.sql.Date to java.util.Calendar" New topic

java.sql.Date to java.util.Calendar

Srividya Shiv
Ranch Hand

Joined: Jul 20, 2000
Posts: 31
Hi All
I have a date field in my database, which I retrieve. This has to be converted to Calendar type before I present. Can anyone suggest a way to do this. The Calendar.setTime(Date)does not serve my purpose.
Apu Nahasapeemapetilon
Ranch Hand

Joined: Sep 06, 2000
Posts: 51
Construct the proper calendar class with the date you retrieve, apu thinks (make an object, then use). The calendar class deprecates the date class (object itself), methinks.
Smack apu upside head iffin he wrong.
Better answer when Apu has JDK in front of him.
Better answer tomorrow......
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
Originally posted by Srividya Shiv:
The Calendar.setTime(Date)does not serve my purpose.

This statement confuses me, this is how the API's intend for this operation to occur. The code to do this is

Calendar c = new GregorianCalendar();

This assumes that dateIn is of type java.sql.Date. This will reassign the values of the Calendar refernce to the Gregorian Calendar Object to the dateIn. Note, to assure all the fields in the GregorianCalendar object represent your date, it is necessary to call a get() on the object (This is a bug IMHO but, it's how the GregorianCalendar works so...)
I hope this helps

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
It is sorta covered in the JavaRanch Style Guide.
subject: java.sql.Date to java.util.Calendar
Similar Threads
util.Date to sql.Date
What is the Expiration time of XML certificate?
getting last row
JBoss started date ???
Java calender get weeks in month, start date and enddate