Thread: formatting a date

formatting a date

From
Fran Fabrizio
Date:
I'm looking all over the place in the Pg docs and Momjian book and
having no luck finding any functions that would turn a timestamp such as
2001-05-08 23:59:59-04 into May 8, 2001.  (i.e. do what date_format()
was doing for me in MySQL.)  Is there equivalent functionality in Pg?

Thanks,
Fran



Re: formatting a date

From
Zak McGregor
Date:
On Thu, 10 May 2001 15:30:01 -0400
Fran Fabrizio <ffabrizio@Exchange.WebMD.net> wrote:

>
> I'm looking all over the place in the Pg docs and Momjian book and
> having no luck finding any functions that would turn a timestamp such as
> 2001-05-08 23:59:59-04 into May 8, 2001.  (i.e. do what date_format()
> was doing for me in MySQL.)  Is there equivalent functionality in Pg?
>

You want to look at to_char().

To get May 10, 2001 you'd need to write something like:

select to_char(now(), 'Month dd, YYYY');

It pads the output of the month to 9 places, btw.

See
http://postgresql.readysetnet.com/users-lounge/docs/7.1/user/functions-formatting.html
 (watch for potential wrapping of the link)

for more info.

--
====================================================================
Zak McGregor
http://www.carfolio.com - Specifications of cars online. Over 7000!
--------------------------------------------------------------------
Of course my password is the same as my pet's name.
My macaw's name was Q47pY!3, but I change it every 90 days.
====================================================================

Re: formatting a date

From
Tom Lane
Date:
Zak McGregor <zak@mighty.co.za> writes:
> It pads the output of the month to 9 places, btw.

You can suppress the padding with the right format-string incantation.
See the docs.

            regards, tom lane

Re: formatting a date

From
Karel Zak
Date:
On Thu, May 10, 2001 at 05:25:04PM -0400, Tom Lane wrote:
> Zak McGregor <zak@mighty.co.za> writes:
> > It pads the output of the month to 9 places, btw.
>
> You can suppress the padding with the right format-string incantation.
> See the docs.

 Yes, use:

 'FMMonth' (Fill Mode) instead 'Month'.

            Karel

--
 Karel Zak  <zakkr@zf.jcu.cz>
 http://home.zf.jcu.cz/~zakkr/

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