I've got the following code which errors and I'm not sure why.
from datetime import datetime
import os
Right_now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print('Right now is ' + Right_now)
filename = 'sysdate.txt'
with open(filename,"r") as fin:
last_date = fin.read()
my_date = datetime.strptime(str(last_date), '%Y-%m-%d %H:%M:%S')
fin.close()
The file contains the following date format 2018-01-18 11:01:54
However I'm getting the following error message..
Right now is 2018-01-18 11:16:13
Traceback (most recent call last):
File "test1.py", line 11, in <module>
my_date = datetime.strptime(str(last_date), '%Y-%m-%d %H:%M:%S')
File "/usr/lib64/python2.7/_strptime.py", line 328, in _strptime
data_string[found.end():])
ValueError: unconverted data remains:
Python version is 2.7.5