Re: How to get DATE in server locale format - Mailing list pgsql-general

From A. Kretschmer
Subject Re: How to get DATE in server locale format
Date
Msg-id 20100111134455.GF22848@a-kretschmer.de
Whole thread Raw
In response to Re: How to get DATE in server locale format  ("Andrus" <kobruleht2@hot.ee>)
Responses Re: How to get DATE in server locale format
List pgsql-general
In response to Andrus :
> >You might be able to get what you want with the to_char() function,
> >if setting datestyle doesn't do the trick for you.
>
> setting datestyle changes style for whole sql statement.
>
> How to get this in a single conversion in sql statement so that other
> expressions in same sql statement are not affected.
>
> to_char() requires hard-coded format.
> Different servers have different locales so that format is not know at
> application design time.
>
> How to get localized date for single conversion inside SELECT statement so
> that it works in different server lc_time settings ?

As Tom said, you can use to_char():

test=*# show lc_time;
   lc_time
-------------
 en_US.UTF-8
(1 row)

test=*# select to_char(current_date, 'TMDay - TMMonth - YYYY');
         to_char
-------------------------
 Monday - January - 2010
(1 row)

test=*# set lc_time = 'de_DE.UTF-8';
SET
test=*# select to_char(current_date, 'TMDay - TMMonth - YYYY');
        to_char
------------------------
 Montag - Januar - 2010
(1 row)


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431  2EB0 389D 1DC2 3172 0C99

pgsql-general by date:

Previous
From: "Andrus"
Date:
Subject: Re: How to get DATE in server locale format
Next
From: Aleksey Onopriyenko
Date:
Subject: migration: parameterized statement and cursor