<?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 Date field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/date-field/m-p/187068#M14385</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a feature class with hundreds of features. The date field in a feature class was populated incorrectly;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1/2/2003.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; i am looking for a python code that can add the zero's to the field to make them correct like; 01/02/2013.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be great.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Dec 2013 16:45:16 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2013-12-03T16:45:16Z</dc:date>
    <item>
      <title>Date field</title>
      <link>https://community.esri.com/t5/python-questions/date-field/m-p/187068#M14385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a feature class with hundreds of features. The date field in a feature class was populated incorrectly;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1/2/2003.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; i am looking for a python code that can add the zero's to the field to make them correct like; 01/02/2013.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be great.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 16:45:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/date-field/m-p/187068#M14385</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2013-12-03T16:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: Date field</title>
      <link>https://community.esri.com/t5/python-questions/date-field/m-p/187069#M14386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input_field = "Date_Time" &amp;nbsp;&amp;nbsp;&amp;nbsp; expression = 'formatDate(!{input_field}!)'.format(input_field=input_field) &amp;nbsp;&amp;nbsp;&amp;nbsp; code_block = """ import dateutil.parser def formatDate(input_date): &amp;nbsp;&amp;nbsp;&amp;nbsp; parsed_date = dateutil.parser.parse(input_date) &amp;nbsp;&amp;nbsp;&amp;nbsp; return parsed_date.strftime("%m/%d/%Y")""" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(input_featureclass, "formatted_output_date", 'DATE') &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(input_featureclass, field_name, expression, "PYTHON_9.3", code_block)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;strftime's %m and %d will produce values with leading zeros where needed, and the dateutil parser will work for dates formatted in other ways as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Shaun&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 18:00:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/date-field/m-p/187069#M14386</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2013-12-03T18:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Date field</title>
      <link>https://community.esri.com/t5/python-questions/date-field/m-p/187070#M14387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you swalbridge for the response, the code you provided only seemed to copy the field but did not add the leading zero's.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The field is a Date field data type, i don't know if that makes a difference or not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Also can this be done in field calculator?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 20:42:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/date-field/m-p/187070#M14387</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2013-12-03T20:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Date field</title>
      <link>https://community.esri.com/t5/python-questions/date-field/m-p/187071#M14388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If the field is a 'date' data type, then it's probably stored correctly, and that's just how ArcGIS is programmed to interpret for display. Dates are a little different than other data types. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can pull the dates out in the format you want using strftime like Shaun said. I'm not sure if you can change the default way they're displayed in ArcMap. I didn't find a setting doing a quick search of the usual spots anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's a link on strftime and the various '%' codes that can be used for the format string:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2.7/library/datetime.html?highlight=datetime#strftime-and-strptime-behavior"&gt;http://docs.python.org/2.7/library/datetime.html?highlight=datetime#strftime-and-strptime-behavior&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 22:25:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/date-field/m-p/187071#M14388</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-12-03T22:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Date field</title>
      <link>https://community.esri.com/t5/python-questions/date-field/m-p/187072#M14389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;oh ok i was expecting to pysically see the "0"&amp;nbsp; in the date field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a ways to do this in Field calculator?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 16:53:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/date-field/m-p/187072#M14389</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2013-12-04T16:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Date field</title>
      <link>https://community.esri.com/t5/python-questions/date-field/m-p/187073#M14390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Nope. I think it would have to be a setting somewhere that lets you adjust how dates are displayed. You can even try manually typing the date in as "01/01/1950" and it will show up as "1/1/1950" after it updates. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And again, it's really just aesthetics. If you want them in a different format for displaying on a map or in a report, you can probably still do that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need to do math on the dates, you can also use python for that. Here's a thread where someone needed to get time deltas in days:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/97156-Calculate-date-difference"&gt;http://forums.arcgis.com/threads/97156-Calculate-date-difference&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 18:15:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/date-field/m-p/187073#M14390</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-12-04T18:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Date field</title>
      <link>https://community.esri.com/t5/python-questions/date-field/m-p/187074#M14391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;msayler thanks for the info and your help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 19:44:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/date-field/m-p/187074#M14391</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2013-12-04T19:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: Date field</title>
      <link>https://community.esri.com/t5/python-questions/date-field/m-p/187075#M14392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you change the output type to string, you'll see the leading zeros. But as msayler mentioned, if you store things as dates, they will be displayed based on locale and not in the specified format explicitly.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 19:08:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/date-field/m-p/187075#M14392</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2013-12-05T19:08:51Z</dc:date>
    </item>
  </channel>
</rss>

