5

What is the difference between java.util.Date and java.sql.Date?

Why can't we use java.util.Date instead of java.sql.Date?

rayryeng
  • 102,964
  • 22
  • 184
  • 193
Chetan Joshi
  • 339
  • 2
  • 5
  • 19
  • 6
    What does the javadoc say? – Reimeus Nov 17 '14 at 18:56
  • Googling java.util.Date and java.sql.Date would have a faster result than asking it here... – Hana Bzh Nov 17 '14 at 19:09
  • 1
    @BzH Actually, the [founders of StackOverflow intended](http://www.joelonsoftware.com/items/2008/04/16.html) for Questions/Answers here to appear as Google search results. Entirely appropriate to ask such Questions here. But rude not to first search for duplicates within StackOverflow. – Basil Bourque Jun 28 '15 at 17:53

1 Answers1

11

Difference between java.util.Date and java.sql.Date in Java from site. It is well explained.

Here are few differences on java.sql.Date and java.util.Date in Java in point format, if you any other difference between them which is worth noting then please post in comments :

  1. As per Javadoc java.sql.Date is a thin wrapper around millisecond value which is used by JDBC to identify an SQL DATE type.

  2. java.sql.Date just represent DATE without time information while java.util.Date represent both Date and Time information. This is the major differences why java.util.Date can not directly map to java.sql.Date.

  3. In order to suppress time information and to confirm with definition of ANSI SQL DATE type, the millisecond values used in java.sql.Date instance must be "normalized by setting the hours, minutes, seconds and milliseconds to zero in the timezone with with DATE instance is associated. In other words all time related information is removed from java.sql.Date class.

kriyeta
  • 695
  • 4
  • 12