Thread: CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP

CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP

From
"sheila bel"
Date:
Hi all,

I wanted to get some information about date and time
stamps and examples of how to use them. In the User
Manual I got referred to functions called CURRENT_DATE,
CURRENT_TIME. I have been literally searching for
hours to find more about them in all the PostgreSQL
manuals, I've used ALL the search engines and did not
find anything. If there is a reference to them they should
be somewhere in there, right?
I'm sorry but dear developers your manual is not user
friendly at all :(
A lot of time gets wasted on finding the information you
need or not finding them at all.

-Sheila


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


Re: [GENERAL] CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP

From
Jose Soares
Date:

sheila bel wrote:

> Hi all,
>
> I wanted to get some information about date and time
> stamps and examples of how to use them. In the User
> Manual I got referred to functions called CURRENT_DATE,
> CURRENT_TIME. I have been literally searching for
> hours to find more about them in all the PostgreSQL
> manuals, I've used ALL the search engines and did not
> find anything. If there is a reference to them they should
> be somewhere in there, right?
> I'm sorry but dear developers your manual is not user
> friendly at all :(
> A lot of time gets wasted on finding the information you
> need or not finding them at all.
>
> -Sheila

You ca use the niladics datetime functions:

               - CURRENT_DATE
               - CURRENT_TIME
               - CURRENT_TIMESTAMP

as  a column default value like:

CREATE TABLE mytb (
    mydt  DATE DEFAULT CURRENT_DATE,
    mytm TIME DEFAULT CURRENT_TIME,
    myts   TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

to insert a value into a column as in:

    INSERT INTO mytb (mydt) VALUES(CURRENT_DATE);

to compare two values as in:

    SELECT * FROM mytb WHERE mytm BETWEEN '1999-12-31 12:30:00' AND
CURRENT_TIMESTAMP;

etc, etc...

--
Jose' Soares
Bologna, Italy                     Jose@sferacarta.com



Re: CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP

From
Sandro Dentella
Date:
You may be right that sometime is not that easy to fin documentation, but to
see how CURRENT_TIME works, try:

erm=> select CURRENT_DATE;
  ?column?
----------
29-02-2000
(1 row

I use it (and the others) in default part of create table:
create table aaa (
   who  text  DEFAULT CURRENT_USER,
   when date  NOT NULL DEFALUT CURRENT_DATE
);

The problem is pg_dump transforms CURRENT_DATE in something w/ "'" that can
not be fed back to    "psql db < file"

By
sandro
*:-)

--
Sandro Dentella  *:-)
e-mail: sandro.dentella@mi.infn.it sandro@ermit.it