Log Parser2.2 TO_DATE& TO_TIMESTAMP转换

时间:2015-02-22 04:24:29

标签: timestamp logparser

刚开始使用日志解析器2.2,所以请原谅我,如果这太傻了,但我仍然坚持将字符串转换为时间戳。

以下Query为我提供了日志文件

中字符串格式的日期输出
$>logparser -i:textline -RTP:-1 "SELECT TOP 1 EXTRACT_SUFFIX(text,0,'TIMESTAMP') from 'C:\ptclmgrd.log' where text like '%TIMESTAMP%'"

EXTRACT_SUFFIX(Text, 0, 'TIMESTAMP')
------------------------------------
 2/6/2015

Statistics:
-----------
Elements processed: 951
Elements output:    1
Execution time:     0.03 seconds

我需要在csv或table中插入上面的字符串,但它应该是日期格式。

如果我尝试以下操作,则输出只是-

$>logparser -i:textline -RTP:-1 "SELECT TOP 1 TO_TIMESTAMP(EXTRACT_SUFFIX(text,0,'TIMESTAMP'),'MM/dd/yyyy') from 'C:\ptclmgrd.log' where text like '%TIMESTAMP%'"

TO_TIMESTAMP(EXTRACT_SUFFIX(Text, 0, 'TIMESTAMP'), 'MM/dd/yyyy')
----------------------------------------------------------------
-

Statistics:
-----------
Elements processed: 951
Elements output:    1
Execution time:     0.01 seconds

我尝试解析的日志文件条目如下:

3:12:40 (lmgrd) TIMESTAMP 2/6/2015

知道什么是错的吗?我希望输出为日期格式的相同字符串。 我也试过了M/d/YYYY但得到了相同的输出。

1 个答案:

答案 0 :(得分:2)

尝试使用小写'y':

M/d/yyyy

以下是时间戳元素的说明:

y       1-digit year
yy      2-digit year
yyy     3-digit year
yyyy    4-digit year
M       month as digit without leading zeros
MM      month as digit with leading zeros
MMM     month as 3-character abbreviation of month name
MMMM    month as full month name
d       day as digit without leading zeros
dd      day as digit with leading zeros
ddd     day as 3-character abbreviation of day name
dddd    day as full day name
h,H     hour without leading zeros
hh,HH   hour with leading zeros
m       minutes without leading zeros
mm      minutes with leading zeros
s       seconds without leading zeros
ss      seconds with leading zeros