PostgreSQL 13に日付の書式設定をする方法

環境
Windows10 64 bit
PostgreSQL 13.2
 
使用例
1.日付の書式「YYYY/MM/DD」を設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select * from to_char(now(),'YYYY/MM/DD') result;
result
------------
2022/01/08
(1)
postgres=# select * from to_char(now(),'YYYY/MM/DD') result; result ------------ 2022/01/08 (1 行)
postgres=# select * from to_char(now(),'YYYY/MM/DD') result;
   result
------------
 2022/01/08
(1 行)

2.24時間表記で日付を設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select * from to_char(now(), 'HH24:MI:SS') result;
result
----------
21:08:23
(1)
postgres=# select * from to_char(now(), 'HH24:MI:SS') result; result ---------- 21:08:23 (1 行)
postgres=# select * from to_char(now(), 'HH24:MI:SS') result;
  result
----------
 21:08:23
(1 行)

3.12時間表記で日付を設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select * From to_char(now(), 'HH:MI:SS') result;
result
----------
09:09:23
(1)
postgres=# select * From to_char(now(), 'HH:MI:SS') result; result ---------- 09:09:23 (1 行)
postgres=# select * From to_char(now(), 'HH:MI:SS') result;
  result
----------
 09:09:23
(1 行)

4.日付の書式「YYYY/MM/DD HH24:MI:SS」を設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select * from to_char(now(),'YYYY/MM/DD HH24:MI:SS') result;
result
---------------------
2022/01/08 21:10:16
(1)
postgres=# select * from to_char(now(),'YYYY/MM/DD HH24:MI:SS') result; result --------------------- 2022/01/08 21:10:16 (1 行)
postgres=# select * from to_char(now(),'YYYY/MM/DD HH24:MI:SS') result;
       result
---------------------
 2022/01/08 21:10:16
(1 行)

 

PostgreSQL

Posted by arkgame