Re: Finding last day in a month - Mailing list pgsql-novice

From Doug Silver
Subject Re: Finding last day in a month
Date
Msg-id 200410191140.44143.dsilver@urchin.com
Whole thread Raw
In response to Finding last day in a month  (Paul Makepeace <postgresql.org@paulm.com>)
List pgsql-novice
On Tuesday 19 October 2004 05:18 am, Paul Makepeace wrote:
> This is perhaps more of a style question. I'm trying to find the 'right'
> way with date/time functions to pull out the last day in a month from a
> set of data that might contain rows that don't fall on the actual last
> date (e.g. Friday 2004-07-30)
>
>  Foo.info_at("2004-07") # contains some logic to make "2004-07-%" for:
>
>  WHERE foo_date LIKE ? ORDER BY foo_date DESC LIMIT 1
>
> This feels quite hacky to me for some reason but at least seems to work.
>
> (I'd originally had foo_date = ?::date+'1month'::interval-'1day'::interval
> !)
>
> Paul

Paul -

Just another suggestion as this probably isn't 'right' either, but it's what I
came up with to figure out the number of days in the previous month (feel
free to tell me a better way if there is one):

select date_part('days',current_date::date -
cast( date_part('days',current_date)||' days' as interval));

-doug

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Vacuum is looping on tables?
Next
From: "Keith Worthington"
Date:
Subject: can a foreign key allow null