Thread: to_date function

to_date function

From
"anru chen"
Date:
Hi all:

i am use postgres 8.2 on windows XP, following select statement

"select to_date('10 August 2007','DD Month YYYY');"
return me 0007-08-10,

if i do "select to_date('10 September 2007','DD Month YYYY');"
result is correct 2007-09-10

seems like "to_date" function only work correctly for current month.
any one know why?

regards,


Re: to_date function

From
"Phillip Smith"
Date:
-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of anru chen
Sent: Friday, 7 September 2007 15:23
To: pgsql-sql@postgresql.org
Subject: [SQL] to_date function

> Hi all:
>
> i am use postgres 8.2 on windows XP, following select statement
>
> "select to_date('10 August 2007','DD Month YYYY');"
> return me 0007-08-10,
>
> if i do "select to_date('10 September 2007','DD Month YYYY');"
> result is correct 2007-09-10

Try using TO_CHAR instead of TO_DATE if it's just for display purposes (I
assume it is)

If it's for comparison purposes, then just cast to a date either by CAST('10
August 2007' AS date) or '10 August 2007'::DATE

~p


THINK BEFORE YOU PRINT - Save paper if you don't really need to print this

*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments
e-mail.


Re: to_date function

From
"A. Kretschmer"
Date:
am  Fri, dem 07.09.2007, um 17:22:30 +1200 mailte anru chen folgendes:
> Hi all:
> 
> i am use postgres 8.2 on windows XP, following select statement
> 
> "select to_date('10 August 2007','DD Month YYYY');"
> return me 0007-08-10,
> 
> if i do "select to_date('10 September 2007','DD Month YYYY');"
> result is correct 2007-09-10
> 
> seems like "to_date" function only work correctly for current month.

No, seems like to_char only work corrently if the length of the month
correctly...

test=*# select to_date('10 August    2007','DD Month YYYY'); to_date
------------2007-08-10
(1 row)

test=*# select to_date('10 August   2007','DD Month YYYY'); to_date
------------0007-08-10
(1 row)



But this is described, see:
http://www.postgresql.org/docs/current/static/functions-formatting.html

,----[  quote  ]
| MONTH    full uppercase month name (blank-padded to 9 chars)
| Month    full mixed-case month name (blank-padded to 9 chars)
| month    full lowercase month name (blank-padded to 9 chars)
`----



Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net


Re: to_date function

From
Tom Lane
Date:
"A. Kretschmer" <andreas.kretschmer@schollglas.com> writes:
> am  Fri, dem 07.09.2007, um 17:22:30 +1200 mailte anru chen folgendes:
>> seems like "to_date" function only work correctly for current month.

> No, seems like to_char only work corrently if the length of the month
> correctly...

You need to use FMMonth not Month if you want it to be lax about the
width of the month field.  (I think we decided that's a bug and 8.3
will take it either way, but existing releases want the FM.)
        regards, tom lane


Re: to_date function

From
"A. Kretschmer"
Date:
am  Fri, dem 07.09.2007, um 10:25:57 -0400 mailte Tom Lane folgendes:
> "A. Kretschmer" <andreas.kretschmer@schollglas.com> writes:
> > am  Fri, dem 07.09.2007, um 17:22:30 +1200 mailte anru chen folgendes:
> >> seems like "to_date" function only work correctly for current month.
> 
> > No, seems like to_char only work corrently if the length of the month
> > correctly...
> 
> You need to use FMMonth not Month if you want it to be lax about the
> width of the month field.  (I think we decided that's a bug and 8.3

Oh, cool, it works.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net