以下の内容はhttps://takuya-1st.hatenablog.jp/entry/2024/02/12/000000より取得しました。


SQLiteでcurrent_time

sqlite で current_time

注意点がある。文字列が主体のsqliteなので、暗黙的文字列キャストが入ったり、datetimeにはタイムゾーンが付与されずUTCである点の2点に配慮すること。

current_timestamp がついているカラムがあって。

sqlite3 database/database.sqlite 'select deleted_at from jobs';
-- Loading resources from /home/takuya/.sqliterc
deleted_at
2024-03-16 06:26:50
2024-03-16 07:26:50
2024-03-16 08:26:51
2024-03-16 08:26:51
2024-03-16 02:42:12

datetime を入れた場合

更新していると、ついついそのまま入れたくなるが、これは、UTCである。

update jobs set deleted_at = datetime() where name = "awxlXViQcg"
 ```

## CURRENT_TIMESTAMP はUTC

SELECT CURRENT_TIMESTAMP ; CURRENT_TIMESTAMP 2024-05-30 03:28:33



## localtime を参照する

SELECT time(current_time, 'localtime') local_time, current_time; local_time|current_time 12:27:22|03:27:22

## 現在の標準時帯に変換する。

select datetime(current_timestamp, 'localtime'); datetime(current_timestamp, 'localtime') 2024-05-30 12:31:52

特に指定しないといい感じに、UTCをLocal変換してあげないといけない

SQLite はちゃんとUTC時刻を扱えるので、カラムにローカルタイムを入れないように注意しないといけない。

## 参考資料

- [https://www.sqlite.org/lang_datefunc.html]
- [https://www.sqlitetutorial.net/sqlite-date-functions/sqlite-current_time/]





## 2024-05-30 追記

ローカルタイムについて記載



以上の内容はhttps://takuya-1st.hatenablog.jp/entry/2024/02/12/000000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14