Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vijay Kumar
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...
 
Clivant Yeo
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
 
Jayashree Menon
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?
 
Shailesh Chandra
Ranch Hand
Posts: 1082
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35266
383
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
 
Rajeshkumar Prakasam
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 ]
 
David Harkness
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic