翻译页面
本页面由 AI 辅助从英文翻译而来。如两者存在差异,以英文版本为准。
DATETIME
根据输入的日期时间和一个或多个修饰符,返回计算得到的日期时间值。
语法
SELECT DATETIME(datetime_expression , modifier, ...) FROM <multipartIdentifier>;
参数
datetime_expression
日期时间值。
modifier
应用于 datetime_expression 的零个或多个修饰符。有关修饰符的更多信息,请参阅日期修饰符。
返回值
返回一个字符串,表示应用 modifier 后输入 datetime_expression 的日期时间。
示例
使用 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。