From: Michael Chaney <mdchaney@michaelchaney.com>
To: pgsql-sql@postgresql.org
To: sgnerd@yahoo.com.sg
Subject: Re: Last day of month
Date: Thu, 26 Feb 2004 10:37:02 -0600
Message-ID: <20040226163702.GC22092@michaelchaney.com> (raw)
In-Reply-To: <542c7f6d5ebe4be44d6b3778850f38ff@biglumber.com>
References: <050b01c3fb9b$de4e1e30$7502a8c0@hdsc.com>
<542c7f6d5ebe4be44d6b3778850f38ff@biglumber.com>
On Thu, Feb 26, 2004 at 03:07:52AM -0000, Greg Sabino Mullane wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> > 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.
select date_trunc('month', current_date + '1 month'::interval) - '1 day'::interval +
(((3 - 7 - to_char(date_trunc('month', current_date + '1 month'::interval) -
'1 day'::interval,'D')::int) %7)||' days')::interval;
The "3" is the day of week (1 = Sunday, 7 = Saturday). This equation
will return the date of the last "x" of the current month. Change
"current_date" to be whatever date you wish to find the last "x" of.
Michael
--
Michael Darrin Chaney
mdchaney@michaelchaney.com
http://www.michaelchaney.com/
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: mdchaney@michaelchaney.com, sgnerd@yahoo.com.sg
Subject: Re: Last day of month
In-Reply-To: <20040226163702.GC22092@michaelchaney.com>
* 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