2008年7月30日水曜日

(WordPress2.6)エントリーの添付ファイルの取り出し方

<?php $attachment = get_posts('numberposts=1&post_type=attachment&post_parent=' . get_the_ID()); ?>
<?php var_dump($attachment); ?>

2008年7月24日木曜日

和暦から西暦への変換をSQLで行う(MySQL)

select case when 0 != locate('平成', <和暦>) then concat_ws('/',
replace(substring_index(<和暦>, '年', 1), '平成', '') - 12 + 2000,
lpad(substring_index(substring_index(<和暦>, '年', -1), '月', 1), 2, 0),
lpad(substring_index(substring_index(<和暦>, '月', -1), '日', 1), 2, 0) ) else
(case when 0 != locate('昭和', <和暦>) then concat_ws('/',
replace(substring_index(<和暦>, '年', 1), '昭和', '') + 25 + 1900,
lpad(substring_index(substring_index(<和暦>, '年', -1), '月', 1), 2, 0),
lpad(substring_index(substring_index(<和暦>, '月', -1), '日', 1), 2, 0) ) else null end) end as ymd from <テーブル>;

<和暦>は以下のようなデータが格納されたフィールド
昭和52年11月8日