翻訳ページ
このページは AI の支援を受けて英語から翻訳されています。内容が異なる場合は英語版が正となります。
DATETIME
入力された日時と 1 つ以上の修飾子から計算した日時値を返します。
構文
SELECT DATETIME(datetime_expression , modifier, ...) FROM <multipartIdentifier>;
引数
datetime_expression
日時値。
modifier
datetime_expression に適用する 0 個以上の修飾子。修飾子の詳細については、日付修飾子 を参照してください。
戻り値
入力 datetime_expression に modifier を適用した日時を表す文字列を返します。
例
localtime 修飾子を使用して UTC をローカル時刻に変換する
SELECT name, timeCreated,
datetime(timeCreated, 'localtime') as local_time_created
FROM google.storage.buckets WHERE project = 'stackql';
日時を UTC に変換する
SELECT name, timeCreated,
datetime('now', 'utc') as now_utc
FROM google.storage.buckets WHERE project = 'stackql';
別の日付を基準に日付を計算する
SELECT name, timeCreated,
datetime(timeCreated, '+24 hours') as a_day_later
FROM google.storage.buckets WHERE project = 'stackql';
指定した日付の後に来る指定曜日を取得する
SELECT name, timeCreated,
datetime(timeCreated, 'weekday 0') as following_sunday
FROM google.storage.buckets WHERE project = 'stackql';
指定した日付の月初を取得する
SELECT name, timeCreated,
datetime(timeCreated, 'start of month') as start_of_month
FROM google.storage.buckets WHERE project = 'stackql';
Unix タイムスタンプを日時に変換する
SELECT datetime(1576417943, 'unixepoch') as date_from_ts
FROM google.storage.buckets WHERE project = 'stackql';
ヒント
詳細については、https://www.sqlite.org/lang_datefunc.html を参照してください。