SQLite strftime() 工作日
SQLite strftime() weekday
我一直在尝试计算在特定工作日创建了多少值,但没有成功:
SELECT count(*) as count FROM packets WHERE strftime("%w", timeIn) = '1';
我在 timeIn
中有这个值
1472434822.60033
1472434829.12632
1472434962.34593
我不知道我做错了什么。
此外,如果我使用这个:
SELECT count(*) as count FROM packets WHERE strftime("%w", timeIn) = '6';
我明白了
2
这毫无意义。先感谢您。
您似乎将日期存储为自 1970 年(Unix 纪元)以来的秒数 - 一种常见的表示形式。 SQLite date functions 接受的时间字符串(参见 时间字符串 部分)默认将数字时间字符串解释为儒略日数字:
Similarly, format 12 is shown with 10 significant digits, but the date/time functions will really accept as many or as few digits as are necessary to represent the Julian day number.
您可以通过以下 SELECT
查看此内容:
SELECT strftime('%Y-%m-%d', 1472428800.6) AS t
其结果是:
4026-48-26
为了将您的日期表示解释为 Unix 纪元,您需要在 strftime
调用中包含 'unixepoch'
:
SELECT strftime('%Y-%m-%d', 1472428800.6, 'unixepoch') AS t
哪个returns:
2016-08-29
如果您将 SELECT
修改为:
SELECT count(*) as count FROM packets WHERE strftime("%w", timeIn, 'unixepoch') = '6'
您应该会看到更符合您预期的结果。
我一直在尝试计算在特定工作日创建了多少值,但没有成功:
SELECT count(*) as count FROM packets WHERE strftime("%w", timeIn) = '1';
我在 timeIn
中有这个值1472434822.60033
1472434829.12632
1472434962.34593
我不知道我做错了什么。
此外,如果我使用这个:
SELECT count(*) as count FROM packets WHERE strftime("%w", timeIn) = '6';
我明白了
2
这毫无意义。先感谢您。
您似乎将日期存储为自 1970 年(Unix 纪元)以来的秒数 - 一种常见的表示形式。 SQLite date functions 接受的时间字符串(参见 时间字符串 部分)默认将数字时间字符串解释为儒略日数字:
Similarly, format 12 is shown with 10 significant digits, but the date/time functions will really accept as many or as few digits as are necessary to represent the Julian day number.
您可以通过以下 SELECT
查看此内容:
SELECT strftime('%Y-%m-%d', 1472428800.6) AS t
其结果是:
4026-48-26
为了将您的日期表示解释为 Unix 纪元,您需要在 strftime
调用中包含 'unixepoch'
:
SELECT strftime('%Y-%m-%d', 1472428800.6, 'unixepoch') AS t
哪个returns:
2016-08-29
如果您将 SELECT
修改为:
SELECT count(*) as count FROM packets WHERE strftime("%w", timeIn, 'unixepoch') = '6'
您应该会看到更符合您预期的结果。