Re: Splitting Timestamps

Поиск
Список
Период
Сортировка
От Reece Hart
Тема Re: Splitting Timestamps
Дата
Msg-id 1153850177.30183.31.camel@tallac.gene.com
обсуждение исходный текст
Ответ на Splitting Timestamps  ("Chris Hoover" <revoohc@gmail.com>)
Список pgsql-general
On Tue, 2006-07-25 at 12:54 -0400, Chris Hoover wrote:
> I know I can do a select to_date(now(),'yyyy-mm-dd') and it will
> return the date.  However, how do I get the time?

Casting is the better option, but the to_date format spec handles a lot
more than just dates. See:

http://www.postgresql.org/docs/8.1/interactive/functions-formatting.html


The casting way:
        rkh@csb-dev=> select '2006-07-25 21:24'::time;
           time
        ----------
         21:24:00

        rkh@csb-dev=> select '2006-07-25 21:24'::date;
            date
        ------------
         2006-07-25

The to_char way:
        rkh@csb-dev=> select to_char(now(),'HH24:MI');
         to_char
        ---------
         10:44

Or the baroque way for your, ahem, timeless applications:
        rkh@csb-dev=> select to_char('2006-07-25 20:24'::timestamp,'MI
        "minutes" past the HH24th hour');
                    to_char
        -------------------------------
         24 minutes past the 20th hour

        rkh@csb-dev=> select to_char('2006-07-25 21:24'::timestamp,'MI
        "minutes" past the HH24th hour');
                    to_char
        -------------------------------
         24 minutes past the 21st hour

-Reece

--
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0


В списке pgsql-general по дате отправления:

Предыдущее
От: Emi Lu
Дата:
Сообщение: Re: gmake Errors: pg_backup_archiver.c: undefined reference
Следующее
От: Chris Browne
Дата:
Сообщение: Re: Splitting Timestamps