Re: extract (dow/week from date)

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: extract (dow/week from date)
Дата
Msg-id 20050821083955.Y93109@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Re: extract (dow/week from date)  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: extract (dow/week from date)  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Sun, 21 Aug 2005, Tom Lane wrote:

> Stephan Szabo <sszabo@megazone.bigpanda.com> writes:
> > I think something like:
> > (CASE WHEN extract(dow from date) = 0 THEN 7 else extract(dow from date))
>
> It's really not that hard:
>
>     (extract(dow from date) + 6) % 7
>
> You can rotate to any week-start day you like by substituting different
> things for "6".

Yeah, mod is probably better and more general than case. It's still fairly
ugly to require a non-trivial expression to get something that's
consistent with the way that extract(week from date) works. ;)

For anyone who is considering using this, to get an actual iso day of
week, I think you'll need to add 1 at the end since that appears to use a
1-7 range. If you're just using it for sorting or the like, you can get
away with not bothering.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: extract (dow/week from date)
Следующее
От: "John Craddock"
Дата:
Сообщение: Windows Installer