概要
日付から年・月・日を個別に取得するには、strftime()関数を使用する。
実行例
環境
- Windows 11
- sqlite Command-Line Shell ver 3.51.3
年を所得する。
年を取得するにはstrftime('%Y', <日付>)を使用する
sqlite> select strftime('%Y', '2026-01-31');
2026
月を取得する
月を取得するにはstrftime('%m', <日付>)を使用する
sqlite> select strftime('%m', '2026-01-31');
01
日を取得する
日を取得するにはstrftime('%d', <日付>)を使用する
sqlite> select strftime('%d', '2026-01-31');
31
参考URL
-
SQLite Query Language: Date And Time Functions(英語)
公式の日時型に関するドキュメント
https://www.sqlite.org/lang_datefunc.html -
Date And Time Functions(英語)
公式のstrftime()関数の書式指定子に関するドキュメント
https://www.sqlite.org/lang_datefunc.html#strftime -
SQLite 備忘録: SQLite3 年内日を求める(sfrftime('%j','yyyy-MM-dd'))
https://sfnovicenotes.blogspot.com/2022/02/sqlite3-sfrftimejyyyy-mm-dd.html -
SQLite 備忘録: SQLite3 日付から曜日を取得する (strftime('%w', 'yyyy-MM-dd'))
https://sfnovicenotes.blogspot.com/2022/02/sqlite3-strftimew-yyyy-mm-dd.html -
SQLite 備忘録: SQLite3 年内週を取得する (strftime('%W', 'yyyy-MM-dd'))
https://sfnovicenotes.blogspot.com/2022/02/sqlite3-strftimew-yyyy-mm-dd_0360293618.html