From: Bruno Wolff III <bruno@wolff.to>
To: John Sebastian N. Mayordomo <quadratini@sni.ph>
Cc: Pgsql-Sql@Postgresql. Org <pgsql-sql@postgresql.org>
Subject: Re: start and end of the week
Date: Thu, 26 Sep 2002 08:26:44 -0500
Message-ID: <20020926132644.GA21571@wolff.to> (raw)
In-Reply-To: <1033037809.16948.2.camel@tiger-work.sni.ph>
References: <1033037809.16948.2.camel@tiger-work.sni.ph>
On Thu, Sep 26, 2002 at 18:56:46 +0800,
"John Sebastian N. Mayordomo" <quadratini@sni.ph> wrote:
>
>
> How do I get the start and end date of the present week?
> Is this possible?
>
> For example this week
> Start = Sept. 22
> End = Sept. 28
The following advice will work on 7.3. For 7.2.2 and earlier it might
not work during a week with a timezone change depending at what time
of day you switch between DST and ST. To fix this you need to cast
current_date to a timestamp without timezone, and I haven't been
able to figure out how to do that and have to run off to a meeting now.
For the first day of the current week use something like:
area=> select current_date - extract(dow from current_date) *
area-> '1 day'::interval;
?column?
---------------------
2002-09-22 00:00:00
(1 row)
For the last day of the week use something like:
area=> select current_date + (6 - extract(dow from current_date)) *
area-> '1 day'::interval;
?column?
---------------------
2002-09-28 00:00:00
(1 row)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, quadratini@sni.ph
Subject: Re: start and end of the week
In-Reply-To: <20020926132644.GA21571@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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