Thread: date functions

date functions

From
"Johnson, Shaunn"
Date:

Howdy:

Silly question.  I want to display the date from
my table in other formats.  Is this possible?

For example, I have this:

[example]

    date
------------
 2000-01-07
 
[/example]

And I want this:

[example]

    date
------------
 20000107

[/example]

And maybe this:

[example]

    date
------------
 01/07/2001

[/example]
 

Any suggestions?  Thanks!

-X

Re: date functions

From
Darren Ferguson
Date:
There is a Postgres function called to_char

Example:

SELECT a.tt_id,
       to_char(a.date_time_submitted,CAST('mm/dd/yyyy' AS text)) AS
date_time_submitted
FROM table a
WHERE a.tt_id = id

RESULT: id | 12/31/2001

Look in the format of the function it is in the documentation. The
formatiing will show you other notations this is just one of them that
fitted on of your examples.

Darren Ferguson

On Fri, 1 Feb 2002, Johnson, Shaunn wrote:

> Howdy:
>
> Silly question.  I want to display the date from
> my table in other formats.  Is this possible?
>
> For example, I have this:
>
> [example]
>
>     date
> ------------
>  2000-01-07
>
> [/example]
>
> And I want this:
>
> [example]
>
>     date
> ------------
>  20000107
>
> [/example]
>
>
> And maybe this:
>
>
> [example]
>
>     date
> ------------
>  01/07/2001
>
> [/example]
>
>
> Any suggestions?  Thanks!
>
> -X
>


Re: date functions

From
Jason Earl
Date:
On Fri, 2002-02-01 at 06:53, Johnson, Shaunn wrote:
> Howdy:
>
> Silly question.  I want to display the date from
> my table in other formats.  Is this possible?
>
> For example, I have this:
>
> [example]
>
>     date
> ------------
>  2000-01-07
>
> [/example]
>
> And I want this:
>
> [example]
>
>     date
> ------------
>  20000107
>
> [/example]

SELECT to_char(current_date, 'YYYYMMDD');

> And maybe this:
>
>
> [example]
>
>     date
> ------------
>  01/07/2001
>
> [/example]

SELECT to_char(current_date, 'DD/MM/YYYY');

> Any suggestions?  Thanks!

The to_char function does precisely what you need.  You can find
excellent documentation in section 4.6 of the PostgreSQL User's guide.

Jason


Re: date functions

From
"omid omoomi"
Date:
hi,
How about using "date_part()" function , to extract yy and mm and dd and
then form them as you wish.  ;)

>From: "Johnson, Shaunn" <SJohnson6@bcbsm.com>
>To: pgsql-general@postgresql.org
>Subject: [GENERAL] date functions
>Date: Fri, 1 Feb 2002 08:53:40 -0500
>
>Howdy:
>
>Silly question.  I want to display the date from
>my table in other formats.  Is this possible?
>
>For example, I have this:
>
>[example]
>
>     date
>------------
>  2000-01-07
>
>[/example]
>
>And I want this:
>
>[example]
>
>     date
>------------
>  20000107
>
>[/example]
>
>
>And maybe this:
>
>
>[example]
>
>     date
>------------
>  01/07/2001
>
>[/example]
>
>
>Any suggestions?  Thanks!
>
>-X




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx