I have essentially the opposite question as this question. I have a string structured as "%y%j"
such that January 1 2017 would be "17001"
and December 31 1995 would be "95365"
.
I essentially need to know what month it is from any given input string. I thought this would be relatively simple. Something like:
input = "95365"
year = int(input[0:2])
day = int(input[2:5])
if day < 32:
month = 1
if day >= 32 and day < 50:
# etc...
what I failed to remember was leap years and how often they repeat. Does anyone have an easy fix? Is there a library for this sort of thing?