我正在尝试将文件读取到mysql数据库,有像这样的时间列格式
05/20/16 01:54:52.797 AM => month/day/year hours:minutes:seconds.millisecond AM/PM
我正在使用以下代码,我无法正确阅读
Drop table temp;
CREATE TABLE temp LIKE messages;
load data infile 'C:/xampp/htdocs/gdxg/test_uploads/test.txt' into table temp fields terminated by '\t' enclosed by '"' lines terminated by '\n' (@Time, State, Name,Pri,Value,)
SET Time = STR_TO_DATE(@Time,'%m/%d/%y %H:%i:%s.%f');
select * from temp limit 10;
它不读取AM / PM
如果我尝试这样做(@Time,'%m/%d/%y %H:%i:%s.%f %p
),请阅读null
?
答案 0 :(得分:0)
您错误地使用了hour
说明符。
说明符说明:
'%H'
- 范围内的小时数(00..23)'%h'
- 范围内的小时数(01..12)'%p'
- AM或PM 在您的查询中将H
更改为h
,'%p'
的使用应该有效。
示例:
mysql> select @t;
+--------------------------+
| @t |
+--------------------------+
| 05/20/16 01:54:52.797 AM |
+--------------------------+
1 row in set (0.00 sec)
mysql> select STR_TO_DATE( @t,'%m/%d/%y %h:%i:%s.%f %p' ) as t;
+----------------------------+
| t |
+----------------------------+
| 2016-05-20 01:54:52.797000 |
+----------------------------+
1 row in set (0.00 sec)
阅读文档: