Converting python time stamp to day of year
<p>How can I convert a python timestamp into day of year:</p>

<pre><code>Timestamp('2015-06-01 00:00:00')
</code></pre>

<p>I want a number where Jan 1 is 1, Jan 2 is 2... Dec 31 is 365 (for a non-leap year)</p>

<p>First, you can convert it to a <code>datetime.datetime</code> object like this:</p>

<pre><code>&gt;&gt;&gt; import datetime
&gt;&gt;&gt; format = "%Y-%m-%d %H:%M:%S"
&gt;&gt;&gt; s = "2015-06-01 00:00:00"
&gt;&gt;&gt; dt = datetime.datetime.strptime(s, format)
</code></pre>

<p>Now you can use the methods on <code>dt</code> to get what you want,except that <code>dt</code> doesn't have the function you want directly, so you need to convert to a time tuple</p>

<pre><code>&gt;&gt;&gt; tt = dt.timetuple()
&gt;&gt;&gt; tt.tm_yday
152
</code></pre>

python datetime