Thread: Select last week

Select last week

From
Bill Moseley
Date:
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@hank.org
Sent from my iMutt