Search Postgresql Archives

Select last week

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm looking at ways to select rows with a timestamp column of "last
week" relative to the current server time.

In 8.3 there's "isoyear" so is this a good approach?

    extract( isoyear from foo_time )
        = extract( isoyear from now() - interval '1 week' )

    AND

    extract( week from foo_time )
        = extract( week from now() - interval '1 week' )

What about before isoyear was available in Postgresql?

Find the week and then add a week for the range?


    date_trunc( 'second', foo_time ) BETWEEN
        date_trunc( 'week', now() - interval '1 week' )
    AND
        date_trunc( 'week', now() - interval '1 week' )
            + interval '1 week' - interval '1 second'

Is there a better approach?



-- 
Bill Moseley
moseley@xxxxxxxx
Sent from my iMutt


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux