Extract day of year and Julian day from a string date
I have a string "2012.11.07" in python. I need to convert it to date object and then get an integer value of day of year and also Julian day . Is it possible? First, you can convert it to a datetime.datetime object like this: >>> import datetime >>> fmt = '%Y.%m.%d' >>> s = '2012.11.07' >>> dt = datetime.datetime.strptime(s, fmt) >>> dt datetime.datetime(2012, 11, 7, 0, 0) Then you can use the methods on datetime to get what you want… except that datetime doesn't have the function you want directly, so you need to convert to a time tuple >>> tt = dt.timetuple() >>> tt.tm_yday 312 The term