时间戳格式 - 从1/1000秒到1/100秒

时间:2017-03-16 09:53:33

标签: sql postgresql

需要将时间戳以1/1000秒分辨率转换为1/100分辨率。我可以为此目的使用to_char(timestamp, text)格式化功能,但需要帮助text才能在此处使用。

输入表(注意 - 此处的时间戳存储为varchar)

+-------------------------+
|       ms1000_val        |
+-------------------------+
| 2017/02/20 08:27:17.899 |
| 2017/02/20 08:23:43.894 |
| 2017/02/20 08:24:41.894 |
| 2017/02/20 08:28:09.899 |
+-------------------------+

输出表格

+------------------------+
|       ms100_val        |
+------------------------+
| 2017/02/20 08:27:17.89 |
| 2017/02/20 08:23:43.89 |
| 2017/02/20 08:24:41.89 |
| 2017/02/20 08:28:09.89 |
+------------------------+

2 个答案:

答案 0 :(得分:6)

您可以在括号中指定它,例如:

t=# select now()::timestamp(2);
          now
------------------------
 2017-03-16 09:55:21.15
(1 row)

因为OP注意到http://rextester.com/CBZ17212会产生不同的结果,然后在psql中运行:

t=# CREATE TABLE Table1
t-#     ("ms1000_val" varchar(23))
t-# ;
CREATE TABLE
t=#
t=# INSERT INTO Table1
t-#     ("ms1000_val")
t-# VALUES
t-#     ('2017/02/20 08:27:17.892'),
t-#     ('2017/02/20 08:23:43.891'),
t-#     ('2017/02/20 08:24:41.897'),
t-#     ('2017/02/20 08:28:09.893')
t-# ;
INSERT 0 4
t=# select ms1000_val::timestamp(2) as time_formatted
t-#        from Table1;
     time_formatted
------------------------
 2017-02-20 08:27:17.89
 2017-02-20 08:23:43.89
 2017-02-20 08:24:41.9
 2017-02-20 08:28:09.89
(4 rows)

答案 1 :(得分:1)

显示这个,我使用to_char和substr,我得到格式yyyy / MM / dd ......

recips = message.Recipients
for recip in recips:
    pa = recip.PropertyAccessor
    smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS)
相关问题