How to get the day of the week from the date in format 20170703
I tried this:
print('1data =', datetime.datetime.today().isoweekday('20170703')) print('2data =', time.strptime(20170703)) print('3data =', datetime.datetime.weekday(20170703)) Parsing date to datetime object (time in this object will be 0 hours without a specific time zone, but it does not matter to us):
>>> d = datetime.datetime.strptime('20170703', '%Y%m%d') >>> print(d) 2017-07-03 00:00:00 >>> type(d) <class 'datetime.datetime'> Call the special isoweekday method on this object:
>>> print(d.isoweekday()) 1 1..6 - Monday .. Saturday, respectively, 7 - Sunday (sometimes Sunday is zero, but according to the documentation, not on isoweekday)
Source: https://ru.stackoverflow.com/questions/813233/
All Articles
print(datetime.datetime.strptime('20170703', '%Y%m%d').isoweekday())- andreymal