X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E3921D801B for ; Thu, 13 Oct 2005 11:31:26 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14513-03 for ; Thu, 13 Oct 2005 14:31:22 +0000 (GMT) Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.91]) by svr1.postgresql.org (Postfix) with ESMTP id 2706FD7EFD for ; Thu, 13 Oct 2005 11:31:24 -0300 (ADT) Received: from Courts-MTA by gwmta.wicourts.gov with Novell_GroupWise; Thu, 13 Oct 2005 09:24:00 -0500 Message-Id: X-Mailer: Novell GroupWise Internet Agent 6.5.4 Date: Thu, 13 Oct 2005 09:23:23 -0500 From: "Kevin Grittner" To: , Cc: Subject: Re: How to insert "date" as timestamp Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003] X-Spam-Level: X-Archive-Number: 200510/60 X-Sequence-Number: 13991 Be careful about that with java.sql.Date. To demonstrate the problem: public class TestDate { public static void main(String[] args) throws InterruptedException { java.util.Date utilDate =3D new java.util.Date(System.curre= ntTimeMillis()); java.sql.Date sqlDate1 =3D new java.sql.Date(utilDate.getTi= me()); Thread.sleep(20L); utilDate =3D new java.util.Date(System.currentTimeMillis())= ; java.sql.Date sqlDate2 =3D new java.sql.Date(utilDate.getTi= me()); System.out.println(sqlDate1 + " equals " + sqlDate2 + " ? = " + sqlDate1.equals(sqlDate2)); =09 java.sql.Timestamp ts =3D new java.sql.Timestamp(sqlDate1.g= etTime()); System.out.println(ts); ts =3D new java.sql.Timestamp(sqlDate2.getTime()); System.out.println(ts); } } I get the following results: 2005-10-13 equals 2005-10-13 ? false 2005-10-13 09:17:40.431 2005-10-13 09:17:40.461 Unfortunately, the burden is on the application programmer to provide a ms value which is at midnight for the default time zone for the JVM when using that constructor. I can't understand that as a design choice, but that's the current reality. -Kevin >>> Roland Walter 10/13/05 4:10 AM >>> The conversion works as the following, i. e.: java.util.Date date =3D new java.util.Date(System.currentTimeMillis()); java.sql.Timestamp timestamp =3D new java.sql.Timestamp(date.getTime()); It is the same for the conversion to java.sql.Date.