Re: Convert number of month to name of month

From: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
To: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
Cc: Matthew Lock <lock_matthew(at)hotmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Convert number of month to name of month
Date: 2002-08-05 11:17:37
Message-ID: 20020805131737.B23020@zf.jcu.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Aug 02, 2002 at 06:59:43PM +0100, Oliver Elphick wrote:
> On Tue, 2002-07-30 at 07:02, Matthew Lock wrote:
> > How do I build a query that takes a field containing the number of the
> > month (1, 2, ..12) and displays it as the name of the month (Jan, Feb,
> > ..Dec)?
> >
> > For example:
> > 1 as Jan
> > 2 as Feb
> > etc.
>
> In plain SQL, use CASE:
>
> SELECT CASE
> WHEN monthno = 1 THEN 'January'
> WHEN monthno = 2 THEN 'February'
> ...
> END AS month
> FROM ...
>
> You could also write a function in PL/PGSQL...

Too long :-)

test=# SELECT to_char(('2000-'|| 8 || '-01')::date , 'Month');
to_char
-----------
August

--
Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message m.malicky 2002-08-05 11:35:54 Problems with ODBC
Previous Message Elielson Fontanezi 2002-08-05 10:58:35 RES: concept question: PostgreSQL vs. Oracle database