Thread: RE: [SQL] datediff function

RE: [SQL] datediff function

From
"Pham, Thinh"
Date:
What happen if i just want to compare using minute only or hour only instead
of day? Is there a function to do that or is postgres only work in day?

T.


> -----Original Message-----
> From: Herouth Maoz [mailto:herouth@oumail.openu.ac.il]
> Sent: Tuesday, August 17, 1999 6:05 AM
> To: tjk@tksoft.com; tpham@mail.priority.net
> Cc: pgsql-sql@postgreSQL.org
> Subject: Re: [SQL] datediff function
> 
> 
> At 02:26 +0300 on 17/08/1999, tjk@tksoft.com wrote:
> 
> 
> >
> > I think what you are looking for is age()
> > E.g.
> >
> > "update schedule set purged = 0 where age('now',dayin) > 
> timespan('30
> >days'::reltime)"
> >
> > Presuming a table such as this:
> >
> > create table schedule (purged int, dayin datetime);
> >
> > This replaces "day" and "timein" with "dayin."
> 
> Basically correct, but if there is an index on dayin, it 
> won't be used. The
> best query to do would be
> 
> WHERE dayin > 'now'::datetime - '30 days'::timespan;
> 
> Herouth
> 
> --
> Herouth Maoz, Internet developer.
> Open University of Israel - Telem project
> http://telem.openu.ac.il/~herutma
> 
> 
> 


RE: [SQL] datediff function

From
Herouth Maoz
Date:
At 16:18 +0300 on 17/08/1999, Pham, Thinh wrote:


> What happen if i just want to compare using minute only or hour only instead
> of day? Is there a function to do that or is postgres only work in day?

No problem, just write 'now'::datetime - '6 hours'::timespan. Or some such.
Please read about the datetime and timespan types in the user guide.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma




Re: [SQL] datediff function

From
Tom Lane
Date:
"Pham, Thinh" <tpham@mail.priority.net> writes:
> What happen if i just want to compare using minute only or hour only instead
> of day? Is there a function to do that or is postgres only work in day?

See date_part().
        regards, tom lane