ライブスケジュール管理ページで以下のテーブル構成の時に終了したライブ情報に"finished"クラスでマークアップしたい。
Table "public.news"
Column | Type | Modifiers
---------+-----------------------------+------------------------------------------------------
id | integer | not null default nextval('public.news_id_seq'::text)
cdate | timestamp without time zone | not null default 'now'
subject | text | not null default ''
comment | text | not null default ''
xyear | integer |
xmonth | integer |
hidden | boolean | not null default false
xday | integer |
timestamp型なら話は早く、now()と比較すればよいのだが今回は「年」「月」「日」がそれぞれバラバラで、これらの情報からTIMESTAMPを作成し、now()と比較したい。この場合以下のSQLでTIMESTAMPを作成できた。
select to_date(xyear || ' ' || xmonth || ' ' || xday, 'YYYY/MM/DD') from news;
最終的にこんなSQLにして「finished」の値を比較してPHP側で判定してクラスをマークアップすれば良し。「年」「月」「日」にデータが入っていない場合はTRUEにしたい為以下のようにした。
SELECT *,
CASE
WHEN TO_DATE(XYEAR || ' ' || XMONTH || ' ' || XDAY, 'YYYYMMDD') > CURRENT_TIMESTAMP
THEN FALSE
ELSE TRUE
END AS FINISHED
FROM NEWS;