snipt

Ctrl+h for KB shortcuts

Python 3

date from iso date string

1
2
3
4
5
6
from datetime import date
from time import strptime

...
date(*strptime('2009-03-28', '%Y-%m-%d')[:3])
...
https://snipt.net/embed/01b319b2eb3f0af63746a93bd69b44d9/
/raw/01b319b2eb3f0af63746a93bd69b44d9/
01b319b2eb3f0af63746a93bd69b44d9
python3
Python 3
6
2019-07-16T10:31:03
True
False
False
/api/public/snipt/4549/
date-from-iso-date-string
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">date</span> </span><span id="L-2"><a name="L-2"></a><span class="kn">from</span> <span class="nn">time</span> <span class="k">import</span> <span class="n">strptime</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="o">...</span> </span><span id="L-5"><a name="L-5"></a><span class="n">date</span><span class="p">(</span><span class="o">*</span><span class="n">strptime</span><span class="p">(</span><span class="s1">&#39;2009-03-28&#39;</span><span class="p">,</span> <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)[:</span><span class="mi">3</span><span class="p">])</span> </span><span id="L-6"><a name="L-6"></a><span class="o">...</span> </span></pre></div> </td></tr></table>
date, python