pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jan de Visser <jdevisser@digitalfairway.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Problem with to_date function
Date: Mon, 22 Aug 2005 16:39:42 -0400
Message-ID: <200508221639.42844.jdevisser@digitalfairway.com> (raw)
In-Reply-To: <430A2827.9060907@secad.to.gov.br>
References: <430A2827.9060907@secad.to.gov.br>

On Monday 22 August 2005 15:31, Gilberto C Andrade wrote:
> Hi,
>
> I would like to know if the following is the expected result:
> from psql:
> bcoproducao=# select to_date(current_date, 'DD/MM/YYYY'), current_date;
>   to_date   |    date
> ------------+------------
>  22/08/2005 | 22/08/2005
> (1 row)
>
> from my jdbc code:
>             rs = stmt.executeQuery("select to_date(current_date,
> 'DD/MM/YYYY'), current_date");
>             while (rs.next()) {
>                 System.out.println(rs.getString(1) + " | "
> +rs.getString(2));
>             }
> result:
>             0028-01-26 | 2005-08-22

Hate to burst your bubble:

psql=# select to_date(current_date, 'DD/MM/YYYY'), current_date;
  to_date   |    date
------------+------------
 0028-01-26 | 2005-08-22
(1 row)

So there is something fishy with your use of to_date, most likely because 
current_date is already of type DATE, and TO_DATE expects a string as it's 
first parameter.

Lemme see:

psql=# select cast( current_date as text );
    text
------------
 2005-08-22
(1 row)

psql=# select to_date( '2005-08-22', 'DD/MM/YYYY');
  to_date
------------
 0028-01-26
(1 row)

So there you have it...

I think that basically you don't need that to_date at all, since you already 
have a date...

JdV!!

>
> Any advice here?
> Thanks!
> Gilberto
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq

-- 
--------------------------------------------------------------
Jan de Visser                     jdevisser@digitalfairway.com

                Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------



view thread (4+ messages)  latest in thread

Message-ID: <200508221639.42844.jdevisser@digitalfairway.com>
Permalink:  ../200508221639.42844.jdevisser@digitalfairway.com/
Also on:    postgresql.org/message-id/200508221639.42844.jdevisser@digitalfairway.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: jdevisser@digitalfairway.com
  Subject: Re: Problem with to_date function
  In-Reply-To: <200508221639.42844.jdevisser@digitalfairway.com>
  References: <430A2827.9060907@secad.to.gov.br> <200508221639.42844.jdevisser@digitalfairway.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox