pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Date arithmatic question
3+ messages / 2 participants
[nested] [flat]

* Date arithmatic question
@ 2000-11-17 22:33  Bryan (Mailing Lists) <bryan_lists@netmeme.org>
  0 siblings, 2 replies; 3+ messages in thread

From: Bryan \(Mailing Lists\) @ 2000-11-17 22:33 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

I have a table "t" with a timestamp column "s". I am trying to issue a query
to find all rows where s is exactly some number of days old (rounded off).

I have tried this:

select * from t where date_part('day', age('now', s)) = ?

But this only looks at the day of the month; e.g. if my parameter is "5",
then it will return all rows that are 5 days old, as well as 1 month 5 days,
as well as 2 months 5 days, etc.

I have also tried this:

select * from t where date_part('day', age('now', s)) = ? and
date_part('month', age('now', status_last_update)) = 0

But this restricts my parameter to 30 days or less; greater than 30 days and
the query doesn't return anything.

What is the correct way to express this?

Thank you,

Bryan





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Date arithmatic question
@ 2000-11-17 22:40  Bryan (Mailing Lists) <bryan_lists@netmeme.org>
  parent: Bryan (Mailing Lists) <bryan_lists@netmeme.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Bryan \(Mailing Lists\) @ 2000-11-17 22:40 UTC (permalink / raw)
  To: Bryan \(Mailing Lists\) <bryan_lists@netmeme.org>; pgsql-general@postgresql.org

Whoops, I had a typo in my translation; the second query I quoted should
read as follows:

select * from t where date_part('day', age('now', s)) = ? and
date_part('month', age('now', s)) = 0

Thanks,

Bryan

----- Original Message -----
From: "Bryan (Mailing Lists)" <bryan_lists@netmeme.org>
To: <pgsql-general@postgresql.org>
Sent: Friday, November 17, 2000 3:33 PM
Subject: [GENERAL] Date arithmatic question


> I have a table "t" with a timestamp column "s". I am trying to issue a
query
> to find all rows where s is exactly some number of days old (rounded off).
>
> I have tried this:
>
> select * from t where date_part('day', age('now', s)) = ?
>
> But this only looks at the day of the month; e.g. if my parameter is "5",
> then it will return all rows that are 5 days old, as well as 1 month 5
days,
> as well as 2 months 5 days, etc.
>
> I have also tried this:
>
> select * from t where date_part('day', age('now', s)) = ? and
> date_part('month', age('now', status_last_update)) = 0
>
> But this restricts my parameter to 30 days or less; greater than 30 days
and
> the query doesn't return anything.
>
> What is the correct way to express this?
>
> Thank you,
>
> Bryan
>




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* RE: Date arithmatic question
@ 2000-11-20 11:43  Francis Solomon <francis@stellison.co.uk>
  parent: Bryan (Mailing Lists) <bryan_lists@netmeme.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Francis Solomon @ 2000-11-20 11:43 UTC (permalink / raw)
  To: Bryan (Mailing Lists) <bryan_lists@netmeme.org>; pgsql-general@postgresql.org

Hi Bryan,

Try this:

select * from t where date_part('days', 'now'::timestamp - s) = ?;

Subtracting two timestamps in this way returns an 'interval', which
(unless you use the 'age' function) doesn't figure out the months and
the years - so 3 months would be rendered as "92 00:00"

Also, note that I think you need to use "days" rather than "day" as the
1st arg to date_part.

Hope this helps you.

Francis Solomon

> -----Original Message-----
> From: pgsql-general-owner@postgresql.org
> [mailto:pgsql-general-owner@postgresql.org]On Behalf Of Bryan (Mailing
> Lists)
> Sent: 17 November 2000 22:34
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] Date arithmatic question
>
>
> I have a table "t" with a timestamp column "s". I am trying
> to issue a query
> to find all rows where s is exactly some number of days old
> (rounded off).
>
> I have tried this:
>
> select * from t where date_part('day', age('now', s)) = ?
>
> But this only looks at the day of the month; e.g. if my
> parameter is "5",
> then it will return all rows that are 5 days old, as well as
> 1 month 5 days,
> as well as 2 months 5 days, etc.
>
> I have also tried this:
>
> select * from t where date_part('day', age('now', s)) = ? and
> date_part('month', age('now', status_last_update)) = 0
>
> But this restricts my parameter to 30 days or less; greater
> than 30 days and
> the query doesn't return anything.
>
> What is the correct way to express this?
>
> Thank you,
>
> Bryan
>
>
>




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2000-11-20 11:43 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-11-17 22:33 Date arithmatic question Bryan (Mailing Lists) <bryan_lists@netmeme.org>
2000-11-17 22:40 ` Bryan (Mailing Lists) <bryan_lists@netmeme.org>
2000-11-20 11:43 ` Francis Solomon <francis@stellison.co.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox