[プログラム] MySqlだけで取得した日付を和暦に変換するSQL
2025-11-21 09:24
38
0
본문
SELECT
CASE
WHEN date_column >= '2019-05-01' THEN
CONCAT('令和', YEAR(date_column) - 2018, '年',
DATE_FORMAT(date_column, '%m月%d日'))
WHEN date_column >= '1989-01-08' THEN
CONCAT('平成', YEAR(date_column) - 1988, '年',
DATE_FORMAT(date_column, '%m月%d日'))
WHEN date_column >= '1926-12-25' THEN
CONCAT('昭和', YEAR(date_column) - 1925, '年',
DATE_FORMAT(date_column, '%m月%d日'))
ELSE
'対象外'
END AS wareki
FROM table_name;
CASE
WHEN date_column >= '2019-05-01' THEN
CONCAT('令和', YEAR(date_column) - 2018, '年',
DATE_FORMAT(date_column, '%m月%d日'))
WHEN date_column >= '1989-01-08' THEN
CONCAT('平成', YEAR(date_column) - 1988, '年',
DATE_FORMAT(date_column, '%m月%d日'))
WHEN date_column >= '1926-12-25' THEN
CONCAT('昭和', YEAR(date_column) - 1925, '年',
DATE_FORMAT(date_column, '%m月%d日'))
ELSE
'対象外'
END AS wareki
FROM table_name;
댓글목록0