在Log Parser中转换Excel序列日期

时间:2016-01-29 13:46:51

标签: excel date logparser

我在Log Parser中转换Excel序列日期(OA日期)。

我有这个问题:

SELECT TOP 10
  Field1 as ExcelSerialDate, /* days since 1900-01-01 */ 
  to_timestamp('1900-01-01 00:00:00', 'yyyy-MM-dd hh:mm:ss') as BaseDate,
  mul(sub(to_real(Field1),2.0),86400.0) as SecondsFromBase,
  add(to_localtime(to_timestamp('1900-01-01 00:00:00', 'yyyy-MM-dd hh:mm:ss')),
  to_timestamp(mul(sub(to_real(Field1),2.0),86400.0))) as Date
FROM 'MyData.txt'

其中MyData.txt每行只包含一个Excel序列日期:

ExcelSerialDate
42397.6668676968
42397.6663989236
42397.664126875
42397.6668321065
42397.6668733565
42397.6668907523
42397.6668711921
42397.6657181597
42397.666233044
42397.6654758681 ...

它提供输出

ExcelSerialDate BaseDate    SecondsFromBase Date
42397.6668676968    01/01/00 12:00:00 AM    3662985617.369  28/01/16 04:00:17 PM
42397.6663989236    01/01/00 12:00:00 AM    3662985576.867  28/01/16 03:59:36 PM
42397.664126875 01/01/00 12:00:00 AM    3662985380.562  28/01/16 03:56:20 PM
42397.6668321065    01/01/00 12:00:00 AM    3662985614.294  28/01/16 04:00:14 PM
42397.6668733565    01/01/00 12:00:00 AM    3662985617.858  28/01/16 04:00:17 PM
42397.6668907523    01/01/00 12:00:00 AM    3662985619.361  28/01/16 04:00:19 PM
42397.6668711921    01/01/00 12:00:00 AM    3662985617.671  28/01/16 04:00:17 PM
42397.6657181597    01/01/00 12:00:00 AM    3662985518.049  28/01/16 03:58:38 PM
42397.666233044 01/01/00 12:00:00 AM    3662985562.535  28/01/16 03:59:22 PM
42397.6654758681    01/01/00 12:00:00 AM    3662985497.115  28/01/16 03:58:17 PM

这是正确的。

这是最好的方法吗?在创建时间戳并将其添加到1900-01-01的基准日期之前,我有两天从序列日期减去2天,这似乎违反直觉。

0 个答案:

没有答案