PostgreSQLで時刻を扱うとき、PHPのdate()で出力しやすいようにUNIXTIME(int型)で保存しています。SQL内での扱いが逆に面倒になるのですが、UNIXTIMEからtimestamp型に戻すTIPS。 create table test ( accesstime integer not null ); select to_char('1970-01-01'::date + (accesstime || 's')::interval, 'YYYY-MM') from test;直接intからintervalに変更できないので(ERROR: cannot cast type integer to intervalが出る)secondsのsを文字列としてつなげてやるとうまくCASTできます。to_charはmktimeみたいな具合に書けます。 月の一覧を出すときはPHPで書