Re: Date for a week day of a month

Поиск
Список
Период
Сортировка
От A. Kretschmer
Тема Re: Date for a week day of a month
Дата
Msg-id 20070703190527.GA28663@a-kretschmer.de
обсуждение исходный текст
Ответ на Date for a week day of a month  (Emi Lu <emilu@encs.concordia.ca>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Stored Procedure: Copy table from; path = text variable
Следующее
От: Nick Barr
Дата:
Сообщение: Re: Date for a week day of a month