Message-ID: From: "davecramer (@davecramer)" To: "pgjdbc/pgjdbc" Date: Mon, 02 Feb 2026 14:31:11 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3924: 0001-01-01 Date not properly saved in database and not properly red from database In-Reply-To: References: List-Id: X-GitHub-Author-Login: davecramer X-GitHub-Comment-Id: 3835481697 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 3924 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3924#issuecomment-3835481697 Content-Type: text/plain; charset=utf-8 Using ``` try (Connection conn = DriverManager.getConnection(url, props)) { try (PreparedStatement ps = conn.prepareStatement("insert into example_table(d) values (?)")){ LocalDate localDate = LocalDate.of(0, 1, 1); java.sql.Date sqlDate = java.sql.Date.valueOf(localDate); ps.setDate(1, sqlDate); ps.execute(); localDate = LocalDate.of (1,1,1); sqlDate = java.sql.Date.valueOf(localDate); ps.setDate(1, sqlDate); ps.execute(); } } try ( Connection conn = DriverManager.getConnection(url, props) ){ try ( Statement statement = conn.createStatement() ) { try (ResultSet rs = statement.executeQuery( "SELECT d FROM EXAMPLE_TABLE") ){ //Retrives value 0001-01-01 already persisted in database while (rs.next()) { d = rs.getDate(1); ts = rs.getTimestamp(1); d1 = rs.getObject(1, LocalDate.class); //-62135751600000 System.out.println( "Get Date: " + d); //Returns 0001-01-03 System.out.println( "Get Timestamp: " + ts); //Returns 0001-01-03 00:00:00 System.out.println( "Get LocalDate: " + d1); //Returns 0001-01-01 } } } } } ``` So with 42.7.8 given a table: ``` table example_table; id | d ----+--------------- 16 | 0001-01-01 BC 17 | 0001-01-01 ``` the code produces ``` Get Date: 0001-01-01 Get Timestamp: 0001-01-01 00:00:00.0 Get LocalDate: 0000-01-01 Get Date: 0001-01-01 Get Timestamp: 0001-01-01 00:00:00.0 Get LocalDate: 0001-01-01 ``` which is clearly wrong as they are 2 different dates. With 42.7.9 we get ``` table example_table; id | d ----+--------------- 18 | 0002-12-30 BC 19 | 0001-12-30 BC ``` ``` Get Date: 0001-01-01 Get Timestamp: 0001-01-01 00:00:00.0 Get LocalDate: -0001-12-30 Get Date: 0001-01-01 Get Timestamp: 0001-01-01 00:00:00.0 Get LocalDate: 0000-12-30 ``` Which is also clearly wrong.