Re: Extracting time from timestamp

From: Darren Ferguson <darren(at)thread(dot)crystalballinc(dot)com>
To: "Shridhar Daithankar<shridhar_daithankar(at)persistent(dot)co(dot)in>" <shridhar_daithankar(at)persistent(dot)co(dot)in>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Extracting time from timestamp
Date: 2003-03-20 18:34:13
Message-ID: Pine.LNX.4.44.0303201333280.5147-100000@thread.crystalballinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

If the field is definately a timestamp field just do the following

SELECT TO_CHAR(stime,'HH24:MI') FROM bookings;

This will give you the desired answer

Darren

On Thu, 20 Mar 2003, Shridhar Daithankar<shridhar_daithankar(at)persistent(dot)co(dot)in> wrote:

> Hi,
>
> I know this is rather stupid but still,
>
> I have a table which has a timestamp field in it and I need to get only time
> part of it. i.e. HH:MI format.
>
> So far I tried,
>
> phd=# select to_timestamp( to_char(stime,'HH24:MI'),'HH24:MI') from bookings;
> to_timestamp
> ------------------------
> 0001-01-01 04:30:00 BC
> 0001-01-01 04:30:00 BC
> 0001-01-01 04:30:00 BC
> (3 rows)
>
>
> I don't know where that BC crept in. It does not show up when I just select
> stime from bookings;
>
> I also tried
>
> phd=# select timestamp to_char(stime,'HH24:MI'),'HH24:MI' from bookings;
> ERROR: parser: parse error at or near "to_char" at character 18
>
> To me that looks like casting a text returned by to_char to timestamp. This
> casting should work if I infer from things like to_char(timestamp
> 'now','HH12:MI:SS') mentioned in postgresql manual(Data type formatting
> function, section 6.7).
>
> Being very stupid, is there any more efficient way of doing this?
>
> TIA..
>
> Shridhar
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

--
Darren Ferguson

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message jwsacksteder 2003-03-20 19:28:22 temporary table oddity
Previous Message Fernando Papa 2003-03-20 17:41:03 Re: using arrays as variable, not as field

Browse pgsql-hackers by date

  From Date Subject
Next Message Barry Lind 2003-03-20 18:41:40 Re: A bad behavior under autocommit off mode
Previous Message Tom Lane 2003-03-20 18:33:16 Re: Faster NUMERIC implementation