extracting date FROM timestamp

Started by javier garcia - CEBASover 22 years ago3 messagesgeneral
Jump to latest
#1javier garcia - CEBAS
rn001@cebas.csic.es

Hi;
Please. Could you tell me the more simple way to extract the 'date' part of a
timestamp value.
I guess we could extract the year, month, and day subfields and concatenate
them. But, isn't there a more direct way?

Best regards,

Javier

#2Arjen van der Meijden
acmmailing@vulcanus.its.tudelft.nl
In reply to: javier garcia - CEBAS (#1)
Re: extracting date FROM timestamp

Javier,

Try casting, like so:
select current_timestamp::date;
(note, pgsql won't be able to use an index for a casted field)

Best regards,

Arjen

javier garcia - CEBAS wrote:

Show quoted text

Hi;
Please. Could you tell me the more simple way to extract the 'date' part of a
timestamp value.
I guess we could extract the year, month, and day subfields and concatenate
them. But, isn't there a more direct way?

Best regards,

Javier

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: javier garcia - CEBAS (#1)
Re: extracting date FROM timestamp

Hello

tsearch2=# select extract(day from current_timestamp);
date_part
-----------
22

or

tsearch2=# select to_char(timestamp 'now','YY DD MM HH12:MI:SS');
to_char
-------------------
03 22 12 12:28:46
(1 ��dka)

Regards
Pavel

On Mon, 22 Dec 2003, javier garcia - CEBAS wrote:

Show quoted text

Hi;
Please. Could you tell me the more simple way to extract the 'date' part of a
timestamp value.
I guess we could extract the year, month, and day subfields and concatenate
them. But, isn't there a more direct way?

Best regards,

Javier

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org