bug in storing date ?

From: Martin Kuba <makub(at)inet(dot)cz>
To: "pgsql-interfaces(at)postgreSQL(dot)org" <pgsql-interfaces(at)postgreSQL(dot)org>
Subject: bug in storing date ?
Date: 1999-06-28 21:47:23
Message-ID: 3777ED6B.52E679AB@inet.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hi,
I have a problem with storing date. I have Postgresql6.4.2
and Java1.2 on Linux.

This is my code for inserting date to column of type "date":

SimpleDateFormat df = new SimpleDateFormat ("dd.MM.yyyy");
ParsePosition pos = new ParsePosition(0);
java.util.Date udate = df.parse("18.06.1999",pos);
java.sql.Date sdate = new java.sql.Date(udate.getTime());
...
PreparedStatement pstmt = con.prepareStatement ("INSERT INTO mytable VALUES(?)");
pstmt.setDate(1,sdate);
pstmt.executeUpdate();

The problem is, that I want to insert the date "18.06.1999" but
I get "19.06.1999" when I do "SELECT". I think the problem
is that the date is stored as time with 00:00:00 hours.
Is it a bug in my code, in Postgresql JDBC driver or somewhere else ?

Please help.

Martin Kuba
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
INET, a.s. Mgr. Martin Kuba
Kralovopolska 139 e-mail: makub(at)inet(dot)cz
601 12 Brno WWW: http://www.inet.cz/~makub/
Czech Republic tel: +420-5-41242414/33
--------------------------------------------------------------------
PGP fingerprint = D8 57 47 E5 36 D2 C1 A1 C3 48 B2 59 00 58 42 27
http://wwwkeys.cz.pgp.net:11371/pks/lookup?op=index&search=makub
--------------------------------------------------------------------

Browse pgsql-interfaces by date

  From Date Subject
Next Message Trans-Euro I.T Ltd (Stephen Martin) 1999-06-28 23:08:47 Visdata
Previous Message Don Garrett 1999-06-28 21:06:51 Re: [ADMIN] float4