Thread: date

date

From
"superboy143 (sent by Nabble.com)"
Date:
Hello,

How can I write an sql query in postgresql so that I can insert a date into
a table in the format DD-MM-YYYY, and when I select the date from the table
I should get the date in the same format.
--
View this message in context: http://www.nabble.com/date-t1097526.html#a2865031
Sent from the PostgreSQL - sql forum at Nabble.com.



Re: date

From
"A. Kretschmer"
Date:
am  09.02.2006, um 22:18:09 -0800 mailte superboy143 (sent by Nabble.com) folgendes:
> 
> Hello,
> 
> How can I write an sql query in postgresql so that I can insert a date into
> a table in the format DD-MM-YYYY, and when I select the date from the table
> I should get the date in the same format.

You can't define the format in the db, but you can define the
output-format with to_char(date, 'DD-MM-YYYY');


HTH, Andreas
-- 
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47215,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net===    Schollglas Unternehmensgruppe    === 


Re: date

From
Ken Hill
Date:
On Fri, 2006-02-10 at 07:38 +0100, A. Kretschmer wrote: <blockquote type="CITE"><pre>
<font color="#000000">am  09.02.2006, um 22:18:09 -0800 mailte superboy143 (sent by Nabble.com) folgendes:</font>
<font color="#000000">> </font>
<font color="#000000">> Hello,</font>
<font color="#000000">> </font>
<font color="#000000">> How can I write an sql query in postgresql so that I can insert a date into</font>
<font color="#000000">> a table in the format DD-MM-YYYY, and when I select the date from the table</font>
<font color="#000000">> I should get the date in the same format.</font>

<font color="#000000">You can't define the format in the db, but you can define the</font>
<font color="#000000">output-format with to_char(date, 'DD-MM-YYYY');</font>


<font color="#000000">HTH, Andreas</font>
</pre></blockquote> You could also try using the data_part() function:<br /><br />
date_part('month',date)||-||date_part('day',date)||-||date_part('year',date)<br/><br /> But I think Andreas' suggestion
isa bit more elegant.<br /><br /> 

Re: date

From
Tom Lane
Date:
Ken Hill <ken@scottshill.com> writes:
> On Fri, 2006-02-10 at 07:38 +0100, A. Kretschmer wrote:
>> You can't define the format in the db, but you can define the
>> output-format with to_char(date, 'DD-MM-YYYY');

> You could also try using the data_part() function:

Setting the DateStyle parameter may also be of use, particularly on the
input side.
        regards, tom lane


Re: date

From
Osvaldo Rosário Kussama
Date:
superboy143 (sent by Nabble.com) wrote:

>Hello,
>
>How can I write an sql query in postgresql so that I can insert a date into
>a table in the format DD-MM-YYYY, and when I select the date from the table
>I should get the date in the same format.
>  
>

See postgresql.conf documentation
(http://www.postgresql.org/docs/8.1/interactive/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-FORMAT):
17. Server Configuration
17.10.2. Locale and Formatting

DateStyle = 'German, dmy'
- output format specification: German
- input/output specification for year/month/day ordering: DMY


postgres=# SHOW datestyle; DateStyle
-------------German, DMY
(1 row)

postgres=# SELECT CURRENT_DATE;   date
------------10.02.2006
(1 row)

postgres=# SELECT to_char('09/03/2005'::date,'dd/mon/yyyy');  to_char
-------------09/mar/2005
(1 row)

[]s
Osvaldo


    
_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora!
http://br.acesso.yahoo.com