This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

how to convert java.util.date to java.sql.date  RSS feed

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

can any body tell me how can I
convert java.util.date to java.sql.date




thanx...
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming your java.util.Date instance is utilDate,

java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

Hopes it helps

Regards,
Clivant
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hullo
One question though?
Is the java.sql.Date, database specific.
Like say, HSQL stores month as 00, whereas Oracle stores month as 01.
Will the java.sql.Date deal with these differences?
 
Ranch Hand
Posts: 1084
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The date-and-time-handling classes in the java.sql package all extend java.util.Date and DATE, TIME, and TIMESTAMP supports standard of SQL92 types.

Read the very good article on java Dates Here



thanks
Shailesh
[ January 20, 2005: Message edited by: Shailesh Chandra ]
 
Author and ninkuma
Marshal
Posts: 66784
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jayashree",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Jayashree Menon
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
First and foremost sorry for the name thing.
Now I am "Jayashree M"

And thanks for the info on date handling.
 
author & internet detective
Marshal
Posts: 38504
653
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jayashree M",
We actually require a last name, not just a last initial.

Thanks,
Jeanne
JDBC Forum Bartender
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, pl help me coding to find out number of days between two dates. The two dates are obtained from access database. And, after getting the date from db, can i assign it directly to java.util.Date, or do i have to assign to java.sql.Date. By the way, for the previous post, i dont think Jayasree would be having a last name as not all indian people have first name, last name etc. Thankz very much.

[ January 31, 2005: Message edited by: Wonderboy Rajesh ]

[ January 31, 2005: Message edited by: Wonderboy Rajesh ]
[ January 31, 2005: Message edited by: Rajeshkumar Prakasam ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since java.sql.Date extends java.util.Date, you can assign it directly to a java.util.Date. Given two Dates (either type), use getTime() to get a long integer representing the number of milliseconds since January 1st, 1970. Subtract one from the other and divide by 1000 * 60 * 60 * 24 for the number of days between them.

All of this information and more is in the JavaDocs. They are extremely useful, and you should get proficient at using them. You'll be able to get answers to some of your questions more quickly than waiting for a reply.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!