Thread: Getting time from date field

Getting time from date field

From
Alejandro Javier Pomeraniec
Date:
Hi !

Is there any way to get the time like the following example ?

'2003-05-11 15:21:21'

should return

'15:21:21'


Thanks !!

Re: Getting time from date field

From
Bruno Wolff III
Date:
On Wed, Nov 05, 2003 at 17:12:12 +0000,
  Alejandro Javier Pomeraniec <apomeraniec@buenosaires.gov.ar> wrote:
> Hi !
>
> Is there any way to get the time like the following example ?
>
> '2003-05-11 15:21:21'
>
> should return
>
> '15:21:21'

You can use the to_char function to convert timestamps to text with
control over the output format.

Re: Getting time from date field

From
Alvaro Herrera
Date:
On Wed, Nov 05, 2003 at 05:12:12PM +0000, Alejandro Javier Pomeraniec wrote:

> Is there any way to get the time like the following example ?
>
> '2003-05-11 15:21:21'
>
> should return
>
> '15:21:21'

Cast it to time:

regression=# SELECT '2003-05-11 15:21:21'::time;
   time
----------
 15:21:21
(1 fila)

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"No necesitamos banderas
No reconocemos fronteras"                  (Jorge González)