0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PostgreSQLのINTERVAL型を、ISO 8601形式(`P2Y3M`みたいなの)に変換する

Last updated at Posted at 2024-06-06

やりたいこと

「2年3ヶ月」を、ISO 8601のP2Y3Mのような形式にしたい。

結論

postgres=# select to_char(interval '2 year 3 month', 'PYY"Y"MM"M"');
 to_char 
---------
 P02Y03M
(1 )

Java側ではこうします。 0203になってても大丈夫みたいです。

java.sql.ResultSet rs = ...;
String value = rs.getString("列名");  // "P02Y03M"のような文字列
java.time.Period period = Period.parse(value);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?