pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
to_date function
5+ messages / 4 participants
[nested] [flat]

* to_date function
@ 2007-09-07 05:22 anru chen <ctx2002@gmail.com>
  2007-09-07 06:17 ` Re: to_date function Phillip Smith <phillip.smith@weatherbeeta.com.au>
  2007-09-07 06:35 ` Re: to_date function A. Kretschmer <andreas.kretschmer@schollglas.com>
  0 siblings, 2 replies; 5+ messages in thread

From: anru chen @ 2007-09-07 05:22 UTC (permalink / raw)
  To: pgsql-sql

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,



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: to_date function
  2007-09-07 05:22 to_date function anru chen <ctx2002@gmail.com>
@ 2007-09-07 06:17 ` Phillip Smith <phillip.smith@weatherbeeta.com.au>
  1 sibling, 0 replies; 5+ messages in thread

From: Phillip Smith @ 2007-09-07 06:17 UTC (permalink / raw)
  To: 'anru chen' <ctx2002@gmail.com>; pgsql-sql

-----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.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: to_date function
  2007-09-07 05:22 to_date function anru chen <ctx2002@gmail.com>
@ 2007-09-07 06:35 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
  2007-09-07 14:25   ` Re: to_date function Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 5+ messages in thread

From: A. Kretschmer @ 2007-09-07 06:35 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: to_date function
  2007-09-07 05:22 to_date function anru chen <ctx2002@gmail.com>
  2007-09-07 06:35 ` Re: to_date function A. Kretschmer <andreas.kretschmer@schollglas.com>
@ 2007-09-07 14:25   ` Tom Lane <tgl@sss.pgh.pa.us>
  2007-09-07 17:41     ` Re: to_date function A. Kretschmer <andreas.kretschmer@schollglas.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2007-09-07 14:25 UTC (permalink / raw)
  To: A. Kretschmer <andreas.kretschmer@schollglas.com>; +Cc: pgsql-sql@postgresql.org, "anru chen" <ctx2002@gmail.com>

"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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: to_date function
  2007-09-07 05:22 to_date function anru chen <ctx2002@gmail.com>
  2007-09-07 06:35 ` Re: to_date function A. Kretschmer <andreas.kretschmer@schollglas.com>
  2007-09-07 14:25   ` Re: to_date function Tom Lane <tgl@sss.pgh.pa.us>
@ 2007-09-07 17:41     ` A. Kretschmer <andreas.kretschmer@schollglas.com>
  0 siblings, 0 replies; 5+ messages in thread

From: A. Kretschmer @ 2007-09-07 17:41 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2007-09-07 17:41 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-09-07 05:22 to_date function anru chen <ctx2002@gmail.com>
2007-09-07 06:17 ` Phillip Smith <phillip.smith@weatherbeeta.com.au>
2007-09-07 06:35 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2007-09-07 14:25   ` Tom Lane <tgl@sss.pgh.pa.us>
2007-09-07 17:41     ` A. Kretschmer <andreas.kretschmer@schollglas.com>

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