formatting a date

Started by Fran Fabrizioalmost 25 years ago4 messagesgeneral
Jump to latest
#1Fran Fabrizio
ffabrizio@Exchange.WebMD.net

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

#2Zak McGregor
zak@mighty.co.za
In reply to: Fran Fabrizio (#1)
Re: formatting a 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.
====================================================================

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Zak McGregor (#2)
Re: formatting a 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

#4Karel Zak
zakkr@zf.jcu.cz
In reply to: Tom Lane (#3)
Re: formatting a 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