Re: Date for a week day of a month

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Date for a week day of a month
Date: 2007-07-03 19:05:27
Message-ID: 20070703190527.GA28663@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am Tue, dem 03.07.2007, um 14:27:24 -0400 mailte Emi Lu folgendes:
> Hello,
>
> Can I know how to get the date of each month's last Thursday please?
>
> For example, something like
>
> Query: select getDateBaseOnWeekday('2007-04-01', 'Last Thursday');
> Result: 2007-04-26

Write you own function. You can get the last date for a month like this:
select '2007-04-01'::date+'1month'::interval-'1day'::interval;

You can get the weekday with:
select extract('dow' from '2007-04-01'::date+'1month'::interval-'1day'::interval);

Now you know the weekday. If this value = 4, its okay. If not, subtract
days until the date is a Thursday.

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Nick Barr 2007-07-03 19:17:11 Re: Date for a week day of a month
Previous Message Richard Huxton 2007-07-03 19:01:03 Re: Stored Procedure: Copy table from; path = text variable