「PostgreSQL 14.4]to_char関数にrmを指定して月をローマ小文字数字で取得する方法
環境
OSバージョンの確認
# cat /etc/redhat-release Rocky Linux release 9.0 (Blue Onyx)
PostgreSQLバージョンの確認
# psql --version psql (PostgreSQL) 14.4
構文
to_char(date '指定日付’, 'rm’)
to_char関数にパターン「rm」を指定して、月をローマ数字で取得します。
パタンー rm
ローマ数字による月 (i-xii: i=1月) (小文字)
使用例
SELECT to_char(date '2022-01-01', 'rm') AS "January", to_char(date '2022-02-01', 'rm') AS "February", to_char(date '2022-03-01', 'rm') AS "March", to_char(date '2022-04-01', 'rm') AS "April", to_char(date '2022-05-01', 'rm') AS "May", to_char(date '2022-06-01', 'rm') AS "June", to_char(date '2022-07-01', 'rm') AS "July", to_char(date '2022-08-01', 'rm') AS "August", to_char(date '2022-09-01', 'rm') AS "September", to_char(date '2022-10-01', 'rm') AS "October", to_char(date '2022-11-01', 'rm') AS "November", to_char(date '2022-12-01', 'rm') AS "December";
実行結果
January February March April May June July August September October November December i ii iii iv v vi vii viii ix x xi xii