From: Frank Bax <fbax@sympatico.ca>
To: pgsql-sql@postgresql.org
Subject: Re: Last day of month
Date: Thu, 26 Feb 2004 09:45:05 -0500
Message-ID: <5.2.1.1.0.20040226093422.029e0560@pop6.sympatico.ca> (raw)
In-Reply-To: <403D7676.6080306@joeconway.com>
References: <542c7f6d5ebe4be44d6b3778850f38ff@biglumber.com>
<542c7f6d5ebe4be44d6b3778850f38ff@biglumber.com>
At 11:30 PM 2/25/04, Joe Conway wrote:
>Greg Sabino Mullane wrote:
>>>How to find the last sunday/mon..../sat of any given month.
>>
>>There is probably a smoother way to do it, but here is a
>>quick little function to do what you ask. Feed it a date
>>and a number, where 0 is Sunday, 1 is Monday, etc.
>
>oops...forget my last reply...I was a bit too quick on the draw. Try this
>instead:
>
>regression=# select date_trunc('month', current_date + '1
>month'::interval) - '1 day'::interval;
> ?column?
>---------------------
> 2004-02-29 00:00:00
>(1 row)
>
>Joe
But the original request was for a specific day-of-week. So use Joe's
answer above to get last day of month, and use 'dow' to determine the
day-of-week of that day. Let's call that dow1. If the day-of-week being
asked for is dow2 then:
if dow1 < dow2
return (last-day-of-month - dow1 - 7 + dow2)
else
return (last-day-of-month - dow1 + dow2)
I'm no good at coding pgsql functions, so I'm not going to attempt proper
syntax.
Frank
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: fbax@sympatico.ca
Subject: Re: Last day of month
In-Reply-To: <5.2.1.1.0.20040226093422.029e0560@pop6.sympatico.ca>
References: <542c7f6d5ebe4be44d6b3778850f38ff@biglumber.com> <5.2.1.1.0.20040226093422.029e0560@pop6.sympatico.ca>
* 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