<?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: Formatting date as string from user input date value in ModelBuilder in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491911#M38552</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/16643"&gt;Neal&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For some reason your function was seeing the "dte" parameter as an integer.&amp;nbsp; Not knowing the entire setup of your model it is difficult to say why.&amp;nbsp; If you look at your error message you can see the date was being passed Calc(6/15/2019), not an integer.&amp;nbsp; By adding single or double quotes around the parameter "%Date%" it forces the parameter to a string.&amp;nbsp; You can then convert that to a date and perform the needed formatting.&amp;nbsp; I hope that helps as to the why.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 15 Jun 2019 22:40:56 GMT</pubDate>
    <dc:creator>LanceCole</dc:creator>
    <dc:date>2019-06-15T22:40:56Z</dc:date>
    <item>
      <title>Formatting date as string from user input date value in ModelBuilder</title>
      <link>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491908#M38549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I cant seem to get best way of handling date fields in ModelBuilder/ArcGIS environment.&amp;nbsp; I created a very simple model in ModelBuilder that accepts a date object (that I used with 'Create Variable) (see first graphic).&amp;nbsp; All I am trying to do is calculate that date object as a string formated in (YYYYmmdd) using the 'Calculate Variable' tool.&amp;nbsp; I expected that since it is a date object that I could simply just use the ".strftime" method to format the date (see 2nd graphic).&amp;nbsp; However I get an error message (3rd graphic) that seems to be implying that the object is an integer.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Can someone point me to how this should be done?&amp;nbsp; I also tried constructing the date using using datetime.datetime.strptime() and then using strftime(), but that didnt work either&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Neal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" height="546" src="https://community.esri.com/legacyfs/online/450467_pastedImage_1.png" width="637" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" height="293" src="https://community.esri.com/legacyfs/online/450469_pastedImage_3.png" width="673" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/450470_pastedImage_4.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jun 2019 13:30:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491908#M38549</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2019-06-15T13:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date as string from user input date value in ModelBuilder</title>
      <link>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491909#M38550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/16643"&gt;Neal&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can place quotes around your "%Date%" parameter in your code&amp;nbsp;and process the value as a string.&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="450471" alt="Calculate Value" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/450471_Capture.PNG" /&gt;@&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jun 2019 20:17:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491909#M38550</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2019-06-15T20:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date as string from user input date value in ModelBuilder</title>
      <link>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491910#M38551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Lance - that worked!.&amp;nbsp; Not sure I understand the "why" this is necessary, but Ill take it.&amp;nbsp; I find dealing with dates when working in model builder/ArcGIS interfaces non-intuitive and more complicated than I would think they should be, but hopefully Ill catch on to the logic at some point&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jun 2019 22:00:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491910#M38551</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2019-06-15T22:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date as string from user input date value in ModelBuilder</title>
      <link>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491911#M38552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/16643"&gt;Neal&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For some reason your function was seeing the "dte" parameter as an integer.&amp;nbsp; Not knowing the entire setup of your model it is difficult to say why.&amp;nbsp; If you look at your error message you can see the date was being passed Calc(6/15/2019), not an integer.&amp;nbsp; By adding single or double quotes around the parameter "%Date%" it forces the parameter to a string.&amp;nbsp; You can then convert that to a date and perform the needed formatting.&amp;nbsp; I hope that helps as to the why.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jun 2019 22:40:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491911#M38552</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2019-06-15T22:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date as string from user input date value in ModelBuilder</title>
      <link>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491912#M38553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is very helpful.&amp;nbsp; I really appreciate your time in help me working through this&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Jun 2019 00:23:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491912#M38553</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2019-06-16T00:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting date as string from user input date value in ModelBuilder</title>
      <link>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491913#M38554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;For some reason your function was seeing the "dte" parameter as an integer.&amp;nbsp; Not knowing the entire setup of your model it is difficult to say why.&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can explain this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;All model&amp;nbsp;elements are strings.&lt;/STRONG&gt;&amp;nbsp;Even if they are dates or extents or feature classes, they are&amp;nbsp;stored and passed from one tool to another&amp;nbsp;using a string representation, with a&amp;nbsp;data type ("Long", "Date", "Extent") to tell tools what data types they are so you can connect them to parameters. For example, if a tool parameter is an integer the model element's data type is what causes&amp;nbsp;you to only see integer parameters in the pick list that appears when you connect the model element to the tool.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However in the Calculate Value tool you need to explicitly include % signs and quotes so Python sees the element value, and knows it is a string, as Python can't see those "handles" on elements, what is in the variable (string) is simply subtitued between the % symbols. So, in your case 6/15/2019 is being interpreted by Python a Python expression of as&amp;nbsp;two integer&amp;nbsp;divisions, left to right (result zero):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;/&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;15&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;/&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2019&lt;/SPAN&gt;
&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To have Python see a string you need to use this expression so Python sees a string:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"%dte%"&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# Python sees "06/15/2019"‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, when we have feature class variables we pass to Calculate Value, it's important to use raw strings so the back slashes aren't interpreted as escape characters:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"%input feature class%"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# Python sees "C:&amp;lt;tab&amp;gt;est"‍&lt;/SPAN&gt;
r&lt;SPAN class="string token"&gt;"%input feature class%"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# Python sees "C:\test"‍‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this is helpful!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:38:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/formatting-date-as-string-from-user-input-date/m-p/491913#M38554</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T21:38:51Z</dc:date>
    </item>
  </channel>
</rss>

