[pgsql-jp: 30057] Re: to_char(XXXX,'W')と木曜日

Youichi Iwakiri yiwakiri @ st.rim.or.jp
2003年 5月 27日 (火) 11:37:38 JST


いわきりです

cdb01160 wrote in <000001c323f4$fa13a650$1401a8c0 @ compevod300> :
>(Postgre)SQLを勉強中の佐藤です。
>
>上記関数は、おかしな動作をします。
>select to_char('2003-5-1'::date,'W');  答えは1.
>select to_char('2003-5-5'::date,'W');  答えは1.
>select to_char('2003-5-9'::date,'W'); 答えは2.
>どうも、「木曜日」区切りになっているようなのですが ?
>手元の本では、「月の初日がある週が第1週」と書いてありますけど、、、
>「カレンダー」では、木曜区切りにはなっていませんよね。
>何処かで、
>「最初の木曜日がある週が第1週」みたいな文書も読んだ気がするのですが、

ISO 8601形式の週表記じゃないですか。

time-interval of seven days, starting on a Monday and identified by its ordinal
 number within a calendar year.

一週間は月曜から日曜まで。

the first calendar week of a year is the one that includes the first Thursday of that year
 and  the last calendar week of a calendar year is the week 
immediately preceding the first calendar week of the next year.

年最初の週は、その年の最初の木曜日を含むこと。

to_char()で、
'W'を使った場合は単純に7日区切りで当月の週を、
'WW'を使った場合は ...
'IW'を使った場合は ...

http://osb.sra.co.jp/PostgreSQL/Manual/PostgreSQL-7.1-ja/functions-formatting.html

見れば、よろしいかと。

-- 
Youichi Iwakiri




pgsql-jp メーリングリストの案内