2

我正在为我的门票生成一份包含创建日期的报告,这真是太棒了。

这是我的sqlite查询(我直接查询数据库)

.header on
.mode csv
.output opentickets.csv
SELECT DISTINCT
   id AS ticket, summary, status, priority, t.type AS type, 
   owner, time as created

  FROM ticket t, ticket_custom q
  LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
  WHERE t.id = q.ticket AND status <> 'closed'
 ORDER BY  priority, time;

但是我在创建时得到的值是垃圾:我得到 1341324096360000 当我应该得到 2012-07-03

我试过 unix 纪元时间转换...查询:

.header on
.mode csv
.output opentickets.csv
SELECT DISTINCT
   id AS ticket, summary, status, priority, t.type AS type, 
   owner, datetime(time, 'unixepoch') as created

  FROM ticket t, ticket_custom q
  LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
  WHERE t.id = q.ticket AND status <> 'closed'
 ORDER BY  priority, time;

我得到:-1413-03-01 13:07:12

我错过了什么?

4

2 回答 2

5

CL 是正确的,时间以微秒为单位存储。您可以在架构中看到时间字段是 int64 并且在.12 的发行说明中说他们已将时间从“自纪元以来的秒数”更改为“自纪元以来的微秒数”。

至于我在 Trac 查询中显示时间的经验,我不需要进行任何转换。这是我用来显示过去 7 天所有更改票证的查询。如您所见,我将工单更改时间显示为选择的一部分,并且 Trac 正确格式化了它。Trac 将自动将创建、修改、日期、时间字段格式化为日期和/或时间。有关更多详细信息,请参阅此Trac wiki 页面

    SELECT 
tc.Ticket AS ticket, 
tc.Time as time, 
c.value as  __group__,
ifnull(tc.Newvalue,0) as total,
tc.Author  AS author,         
tc.Field as field     
from ticket_change tc 
LEFT JOIN ticket t on t.id = tc.ticket
LEFT JOIN ticket_custom c on c.ticket = tc.ticket and c.name= 'customer'
LEFT JOIN ticket_custom tt on tt.ticket = tc.ticket and tt.name = 'totalhours'
where field = 'hours' and c.Value is not null
and tc.Time > strftime('%s',CURRENT_DATE-7) +0
and tc.Time < strftime('%s',CURRENT_DATE) +0
and tc.Author = $USER
and tt.value is not null

如果您想做一些特殊的格式化,请按时查看SQLite 文档,但这里有一个简单的示例

strftime('%m/%d/%Y', time / 1000000, 'unixepoch', 'localtime') 

我希望这有帮助。

于 2012-10-24T12:57:38.357 回答
2

Unix 时间戳以秒为单位,但这些值似乎是微秒:

> SELECT datetime(1341324096360000 / 1000000, 'unixepoch');
2012-07-03 14:01:36
于 2012-10-24T08:17:32.763 回答