<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python complains about date format? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494168#M38775</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thomas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect it's your locale setting. I can reproduce the same error if i set my locale explicitly to German_Germany, may be try explicitly setting your locale as&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;locale.setlocale(locale.LC_ALL, 'English_US')&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;IMG alt="Untitled.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/15086_Untitled.png" style="width: 620px; height: 196px;" /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Below is the code that produced this error.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14115622429385961 jive_text_macro" jivemacro_uid="_14115622429385961"&gt;
&lt;P&gt;import arcpy, datetime, locale&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;layer = arcpy.GetParameter(0)&lt;/P&gt;
&lt;P&gt;arcpy.AddMessage(layer)&lt;/P&gt;
&lt;P&gt;locale.setlocale(locale.LC_ALL, 'German_Germany')&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(layer, ["ddMMMYYYY", "YYYY_MM_dd"]) as UCursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; for row in UCursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; origDate = datetime.datetime.strptime(row[0], '%d%b%Y')&lt;/P&gt;
&lt;P&gt;&amp;nbsp; row[1] = datetime.date.strftime(origDate, '%Y-%m-%d')&lt;/P&gt;
&lt;P&gt;&amp;nbsp; UCursor.updateRow(row)&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Sep 2014 12:37:25 GMT</pubDate>
    <dc:creator>RiyasDeen</dc:creator>
    <dc:date>2014-09-24T12:37:25Z</dc:date>
    <item>
      <title>Python complains about date format?</title>
      <link>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494167#M38774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to convert some date strings into correct dates, to be recognized by Python and ArcGIS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Setup:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ArcGIS 10.2.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Python 2.7.5&lt;/P&gt;&lt;P&gt;All data are located within a FGDB...&lt;/P&gt;&lt;P&gt;I set the workspace to be the FGDB, created a new Field of type data in my table and went on with the following things within the IDLE Shell&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import datetime&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor(myTable, [field01, field02]) as UCursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in UCursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; origDate = datetime.datetime.strptime(row[0], '%d%b%Y')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = datetime.date.strftime(origDate, '%Y-%m-%d')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UCursor.updateRow(row)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Things work fine until the input string is '11MAY2004', where I get the following error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "&amp;lt;pyshell#9&amp;gt;", line 4, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; origDate = datetime.datetime.strptime(row[0], '%d%b%Y')&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Python27\ArcGISx6410.2\lib\_strptime.py", line 325, in _strptime&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (data_string, format))&lt;/P&gt;&lt;P&gt;ValueError: time data '11MAY2004' does not match format '%d%b%Y'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did try the whole thing in plain Python (same shell) before, where I simply did:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;orig = '11MAY2004'&lt;/P&gt;&lt;P&gt;x = datetime.datetime.strptime(orig, '%d%b%Y')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and this works without any problem!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can somebody enlighten me where I go wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 09:28:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494167#M38774</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2014-09-24T09:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python complains about date format?</title>
      <link>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494168#M38775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thomas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect it's your locale setting. I can reproduce the same error if i set my locale explicitly to German_Germany, may be try explicitly setting your locale as&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;locale.setlocale(locale.LC_ALL, 'English_US')&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;IMG alt="Untitled.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/15086_Untitled.png" style="width: 620px; height: 196px;" /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Below is the code that produced this error.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14115622429385961 jive_text_macro" jivemacro_uid="_14115622429385961"&gt;
&lt;P&gt;import arcpy, datetime, locale&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;layer = arcpy.GetParameter(0)&lt;/P&gt;
&lt;P&gt;arcpy.AddMessage(layer)&lt;/P&gt;
&lt;P&gt;locale.setlocale(locale.LC_ALL, 'German_Germany')&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(layer, ["ddMMMYYYY", "YYYY_MM_dd"]) as UCursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; for row in UCursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; origDate = datetime.datetime.strptime(row[0], '%d%b%Y')&lt;/P&gt;
&lt;P&gt;&amp;nbsp; row[1] = datetime.date.strftime(origDate, '%Y-%m-%d')&lt;/P&gt;
&lt;P&gt;&amp;nbsp; UCursor.updateRow(row)&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 12:37:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494168#M38775</guid>
      <dc:creator>RiyasDeen</dc:creator>
      <dc:date>2014-09-24T12:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python complains about date format?</title>
      <link>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494169#M38776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I get an error with strftime if I try to use %T, which according to &lt;A href="http://www.tutorialspoint.com/python/time_strftime.htm"&gt;TutorialsPoint &lt;/A&gt;is a valid format, a shortcut for %H%M%S.&lt;/P&gt;&lt;P&gt;But this raises an error, and in fact is not in the Python.org &lt;A href="https://docs.python.org/2/library/time.html#time.strftimehttp://"&gt;documentation &lt;/A&gt;for strftime. The point being that there's erroneous information out on the web. Who knew? &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/grin.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it's a locale issue, you may want to look at:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;A class="internal reference" href="https://docs.python.org/2/library/time.html#time.strftime" title="time.strftime"&gt;&lt;TT class="xref py-func py docutils literal"&gt;&lt;SPAN class="pre"&gt;strftime()&lt;/SPAN&gt;&lt;/TT&gt;&lt;/A&gt; returns a locale depedent byte string; the result may be converted to unicode by doing &lt;TT class="docutils literal"&gt;&lt;SPAN class="pre"&gt;strftime(&amp;lt;myformat&amp;gt;).decode(locale.getlocale()[1])&lt;/SPAN&gt;&lt;/TT&gt;.&lt;/P&gt;&lt;P&gt;also from the same documentation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Sep 2014 14:02:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494169#M38776</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-09-24T14:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python complains about date format?</title>
      <link>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494170#M38777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yes I can confirm that is has something to do with locale. A first solution was to change the format localization from Danish to English and restart the shell. I have to follow up on your suggestion to use the locale package. Thanks so far.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Sep 2014 07:10:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494170#M38777</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2014-09-25T07:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python complains about date format?</title>
      <link>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494171#M38778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;never saw a '%T' and hey Tutorialspoint is a nice starting but nothing official and I would rather stick to the official docs. I solved the problem quick and dirty, and the task is pushing me further, but as soon as I have the time to check on locale and decode I will give it a try.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bests, Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Sep 2014 07:13:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-complains-about-date-format/m-p/494171#M38778</guid>
      <dc:creator>TomGeo</dc:creator>
      <dc:date>2014-09-25T07:13:47Z</dc:date>
    </item>
  </channel>
</rss>

