X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 33064D1B57C for ; Thu, 26 Feb 2004 04:31:27 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 67829-10 for ; Thu, 26 Feb 2004 00:31:25 -0400 (AST) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id D4910D1B51F for ; Thu, 26 Feb 2004 00:31:24 -0400 (AST) Received: from [192.168.5.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 1012438; Wed, 25 Feb 2004 20:27:25 -0800 Message-ID: <403D7676.6080306@joeconway.com> Date: Wed, 25 Feb 2004 20:30:46 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Greg Sabino Mullane Cc: pgsql-sql@postgresql.org, sgnerd@yahoo.com.sg Subject: Re: Last day of month References: <542c7f6d5ebe4be44d6b3778850f38ff@biglumber.com> In-Reply-To: <542c7f6d5ebe4be44d6b3778850f38ff@biglumber.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/357 X-Sequence-Number: 17047 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