Reputation: 945
I want to change outlook creationTime format.
for message in sub.Items:
subject = message.subject
body = message.body
sendTime = message.CreationTime
I get the message creationTime
for using message.CreationTime
.
When I print the sendTime
, the result is 04/15/16 17:22:29.
So I used strftime
to change the date format but it does not work.
I imported such library in my source code.
import win32com.client
from datetime import datetime, date, time
import string
import pymysql
But an error occured:
Traceback (most recent call last):
File "D:\20_log\outlook\outlook.py", line 164, in <module> main()
File "D:\20_log\outlook\outlook.py", line 161, in main get_outlook_message()
File "D:\20_log\outlook\outlook.py", line 56, in get_outlook_message
sendTime.strftime('%H:%M:%S')
AttributeError: strftime
How can I change the outlook creationTime
format?
Upvotes: 1
Views: 1542
Reputation: 66215
MailItem.CreationTime
is DateTime value, it does not have any format - it is not a string. On the low level (COM), it is an 8 byte float with the integer number being the number of days since 1/1/1900
and the fractional part being the time of the day.
Upvotes: 1
Reputation: 123453
Since (according to your comments) sendTime
is a string, you can parse it into a time.struct_time
using time.strptime()
, which can then be formatted with time.strftime()
like you're attempting to do.
import time
sendTime = '04/15/16 17:22:29' # example value of message.CreationTime
# parse sendTime into a time.struct_time
sendTime_st = time.strptime(sendTime, '%m/%d/%y %H:%M:%S')
# format the returned struct_time into the desired format
print(time.strftime('%H:%M:%S', sendTime_st))
# another example
print(time.strftime('%a, %m-%b-%y at %H:%M:%S', sendTime_st))
Output:
17:22:29
Fri, 04-Apr-16 at 17:22:29
Upvotes: 1