<p dir="auto">Just noting that there was a PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="480195158" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/14264" data-hovercard-type="pull_request" data-hovercard-url="/numpy/numpy/pull/14264/hovercard" href="https://github.com/numpy/numpy/pull/14264">#14264</a> a year ago to try and add a <code class="notranslate">strftime</code> method to datetime64 object. Wonder if it might be resurrected??? :issue:<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="479148168" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/14243" data-hovercard-type="issue" data-hovercard-url="/numpy/numpy/issues/14243/hovercard" href="https://github.com/numpy/numpy/issues/14243">#14243</a></p>
<p dir="auto">To make it a little more friendly for packages downstream like Pandas it helps to compare synonomously with Python datetime and something like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import datetime as dt
import numpy as np

date = dt.datetime.strptime('2020-06-30', format='%Y-%m-%d')
date.strftime('%Y-%m-%d')
dt.datetime.strftime(date, &quot;%Y-%m-%d&quot;)

date64 = np.datetime64('2012-06-30T20:00')
np.datetime_as_string(date64, unit='D')
# nice with a direct date64.strftime(format) method.."><pre class="notranslate"><code class="notranslate">import datetime as dt
import numpy as np

date = dt.datetime.strptime('2020-06-30', format='%Y-%m-%d')
date.strftime('%Y-%m-%d')
dt.datetime.strftime(date, "%Y-%m-%d")

date64 = np.datetime64('2012-06-30T20:00')
np.datetime_as_string(date64, unit='D')
# nice with a direct date64.strftime(format) method..
</code></pre></div>
<p dir="auto">Looking at extending the support for <code class="notranslate">datetime64</code> in matplotlib, in particular to allow plotting times that are outside years 0001-9999.  Lots of science applications have millennial time scales, so being able to have support for a large time range is desirable, and is a definite strength of <code class="notranslate">datetime64</code>.</p>
<p dir="auto">However, our tick formatters use <code class="notranslate">datetime.strftime</code>, and allow all the formatting strings for those (i.e. %Y, %y, %x, %g etc).  However, we can't convert <code class="notranslate">datetime64</code> to <code class="notranslate">datetime</code> for years outside 0001-9999 so we can't use strftime (directly).</p>
<p dir="auto">Is there any way to get what we want?  We can do a song and dance to force a <code class="notranslate">datetime64</code> to be between 0001-9999 by adding or subtracting multiples of 400 years, and then reformatting just the year part of the string, but it would be nice if there were something more robust.  Not sure if <code class="notranslate">datetime_as_string</code> could be enhanced to take a <code class="notranslate">fmt=str</code> optional kwarg?</p>