Thread: Date Parse

Date Parse

From
pocm@rnl.ist.utl.pt (Paulo J. Matos)
Date:
Hi all,

I have a field in a table of type date. 
In a results set I get some dates. How can I access the month in
those dates?

Best regards,

-- 
Paulo J. Matos : pocm(_at_)rnl.ist.utl.pt
Instituto Superior Tecnico - Lisbon    
Software & Computer Engineering - A.I.- > http://www.rnl.ist.utl.pt/~pocm ---    Yes, God had a deadline...    So, He
wroteit all in Lisp!
 



Re: Date Parse

From
"postgresql"
Date:
Paulo,

given your_table has a column  called date_col.

SELECT to_char(date_col, 'Month') FROM your_table WHERE 
something is true;
Will give you a response of the month spelled out. Change the 
'Month' to 'MM' and you get a two character string from 01 to 12 for the 
month. Change it to 'month' and you get a lower case month, 
(january).

check the docs on formatting:
http://www.postgresql.org/idocs/index.php?functions-formatting.html


Ted

-----Original Message-----
From: pocm@rnl.ist.utl.pt (Paulo J. Matos)
To: pgsql-sql@postgresql.org
Date: 30 Jan 2002 00:04:18 +0000
Subject: [SQL] Date Parse

> Hi all,
> 
> I have a field in a table of type date. 
> In a results set I get some dates. How can I access the month in
> those dates?
> 
> Best regards,
> 
> -- 
> Paulo J. Matos : pocm(_at_)rnl.ist.utl.pt
> Instituto Superior Tecnico - Lisbon    
> Software & Computer Engineering - A.I.
>  - > http://www.rnl.ist.utl.pt/~pocm 
>  ---    
>     Yes, God had a deadline...
>         So, He wrote it all in Lisp!
> 
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org




Re: Date Parse

From
"Andrew G. Hammond"
Date:
Use the SQL EXTRACT function.  This is covered in the docs at
http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT

Briefly, SELECT EXTRACT(MONTH FROM TIMESTAMP '2001-02-30 12:34:56');
returns 2

On Tue, 2002-01-29 at 19:04, Paulo J. Matos wrote:

> I have a field in a table of type date.
> In a results set I get some dates. How can I access the month in
> those dates?

--
Andrew G. Hammond     mailto:drew@xyzzy.dhs.org
http://xyzzy.dhs.org/~drew/
56 2A 54 EF 19 C0 3B 43 72 69 5B E3 69 5B A1 1F
613-389-5481
5CD3 62B0 254B DEB1 86E0  8959 093E F70A B457 84B1
"To blow recursion you must first blow recur" -- me

Re: Date Parse

From
Chris Ruprecht
Date:
Hi Paulo,

this should do for example:
select substr( 'now'::date, 6, 2 );

Best regards,
Chris

At 00:04 +0000 01/30/2002, Paulo J. Matos wrote:
>Hi all,
>
>I have a field in a table of type date.
>In a results set I get some dates. How can I access the month in
>those dates?
>
>Best regards,
>
>--
>Paulo J. Matos : pocm(_at_)rnl.ist.utl.pt
>Instituto Superior Tecnico - Lisbon   
>Software & Computer Engineering - A.I.
>  - > http://www.rnl.ist.utl.pt/~pocm
>  ---
>    Yes, God had a deadline...
>        So, He wrote it all in Lisp!
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: Have you searched our list archives?
>
>http://archives.postgresql.org


-- 
Chris Ruprecht
Network grunt and bit pusher extraordinaíre

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com