Re: Constructors for dates, times, and timestamps - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Constructors for dates, times, and timestamps
Date
Msg-id 20070301163959.GB1705@svana.org
Whole thread Raw
In response to Constructors for dates, times, and timestamps  ("Andrew T. Robinson" <atr@nmi.net>)
List pgsql-general
On Tue, Feb 27, 2007 at 07:47:32AM -0500, Andrew T. Robinson wrote:
> Migrating from DB/2 6.1 to PostgreSQL 8.1.4,
>
> The following work under DB/2, but I can find no analog in the
> PostgreSQL documentation:
>
>    time('00:00:00')  [there is to_date() and to_timestamp(), but no
> to_time()?]

Well, you can always use to_timestamp and then cast to time, but this
also works:

# select "time"('00:00:00');
   time
----------
 00:00:00
(1 row)

I can't explain the need for the quotes, some kind of grammer issue.

>    timestamp(u.date, u.time) [where u.date is of type DATE and u.time
> is of type TIME]

There is the function datetime_pl(date,time) whic does that, but most
people just use +'

# select '2007-05-02'::date + '22:33:44'::time;
      ?column?
---------------------
 2007-05-02 22:33:44
(1 row)

You can wrap it into a simple function if that makes it easier to
understand.

Oddly, the documentation indeed doesn't list all the functions, but the
operators will do what you want also.

http://www.postgresql.org/docs/current/static/functions-datetime.html

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: creating a function with a variable table name
Next
From: "Albe Laurenz"
Date:
Subject: Re: cast bytea to text