• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41855
904
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic