What I am trying to do is see if date
is in 1 week from currdate
from datetime import datetime, timedelta
import yagmail
year = datetime.now().year
month = datetime.now().month
day = datetime.now().day
currdate = '{}-{}-{}'.format(year, month, day)
currdate = datetime.strptime(currdate, '%Y-%m-%d')
date = '2018-04-01'
days = currdate - timedelta(int(date[-2:]))
days = str(days)
print(days)
if days[8:11] == '07':
yag = yagmail.SMTP("#########@gmail.com", "######")
content = ['One Of Your Homework\'s Is Due In 1 Week!']
yag.send('##########@gmail.com', 'Homework Due Soon!', content)
else:
print('It Isn\'t')
But it prints:
2018-04-07 00:00:00
It Isnt't
And I'm not sure why. Because days[8:11]
is 07
.
It is not 07
. It's 07
(note the trailing space).
The following change will work:
if int(days[8:11]) == 7: