Re: Formatting a month in query output

From: Alexander Borkowski <alexander(dot)borkowski(at)abri(dot)une(dot)edu(dot)au>
To: "Rodolfo J(dot) Paiz" <rpaiz(at)simpaticus(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Formatting a month in query output
Date: 2005-01-25 02:06:18
Message-ID: 41F5A99A.7050602@abri.une.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi Rodolfo,

> I have a query which needs to provide a monthly report. Thanks to the
> date_trunc() function someone mentioned in a thread earlier today, I got
> the query working properly. However, each month is '2004-10-01 00:00:00'
> and I would like to have "October 2004".
>
> Which function, if any, would help me do this formatting trick? And
> where can I read more about it?

Try to_char(the_date_you_want_to_display, 'MonthYYYY') for that. Note
that there actually is no need to use date_trunc here as to_char will
only represent only what you ask for anyway. You can find more in the
PostgreSQL Online Manual at http://www.postgresql.org/docs/manuals/
(select the one for the version you are using). The chapter is
'Functions and Operators', section 'Data Type Formatting Functions'.

HTH,

Alex

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Sean Davis 2005-01-25 02:08:58 Re: Formatting a month in query output
Previous Message Sean Davis 2005-01-25 02:05:44 Re: Output HTML, or just a handle?