python - Strptime Weeks Error -
i'm writing scripts require manipulating week of year is. inputs in form yyyyww
, such '201435'
.
during attempts use strptime
it, reason, defaults first of year. example:
import datetime test = '201435' test = datetime.datetime.strptime(test,'%y%u') print(test)
outputs
2014-01-01 00:00:00
i'm not sure why it's doing so. using time
module or replacing %u
%w
has exact same result.
read note 6 in the documentation:
when used
strptime()
method,%u
,%w
used in calculations when day of week , year specified.
therefore, don't specify day in week, week number ignored , first of year. fix that, add day:
>>> datetime.datetime.strptime('2014350', '%y%u%w') # ^ here ^ , here datetime.datetime(2014, 8, 31, 0, 0)
Comments
Post a Comment