Re: How to get DATE in server locale format

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to get DATE in server locale format
Date: 2010-01-11 13:44:55
Message-ID: 20100111134455.GF22848@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Aleksey Onopriyenko 2010-01-11 14:16:38 migration: parameterized statement and cursor
Previous Message Thilo Schneider 2010-01-11 13:33:03 Re: Set Returning C-Function with cache over multiple calls (with different arguments)