Re: Splitting Timestamps

From: Reece Hart <reece(at)harts(dot)net>
To: Chris Hoover <revoohc(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Splitting Timestamps
Date: 2006-07-25 17:56:16
Message-ID: 1153850177.30183.31.camel@tallac.gene.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)csb-dev=> select '2006-07-25 21:24'::time;
time
----------
21:24:00

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

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

Or the baroque way for your, ahem, timeless applications:
rkh(at)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(at)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Emi Lu 2006-07-25 17:56:21 Re: gmake Errors: pg_backup_archiver.c: undefined reference
Previous Message Chris Browne 2006-07-25 17:55:14 Re: Splitting Timestamps