<?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 Code in python the equivalent of the VB Format function in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187249#M14403</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using ArcGIs 9.3 and Model Bulder. I was able to code a calculate field in VB that formats a field as follows Format("08.00.00") and converts it to "08:00:00 AM"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I do the same thing in Python (phyton 3 or python)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please advise!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Jan 2011 11:32:55 GMT</pubDate>
    <dc:creator>JoseSanchez</dc:creator>
    <dc:date>2011-01-14T11:32:55Z</dc:date>
    <item>
      <title>Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187249#M14403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using ArcGIs 9.3 and Model Bulder. I was able to code a calculate field in VB that formats a field as follows Format("08.00.00") and converts it to "08:00:00 AM"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I do the same thing in Python (phyton 3 or python)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please advise!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 11:32:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187249#M14403</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2011-01-14T11:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187250#M14404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This will work to edit the string directly. Or you can use the time module and do all sorts of things to it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; 
astring="08.00.00".replace('.',':')
if int(astring.split(':')[0]) &amp;lt; 12:
&amp;nbsp;&amp;nbsp;&amp;nbsp; astring+=' AM'
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; astring+=' PM'
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:28:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187250#M14404</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2021-12-11T09:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187251#M14405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;i have the same problem,how can i write expression by Python in Raster Calculator,i have many problem with applied expression (syntax) by Python, there were many different in VB and Python, so can any one help me how can i do it in Python....please&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 12:39:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187251#M14405</guid>
      <dc:creator>MustafaELHalwagy</dc:creator>
      <dc:date>2011-01-14T12:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187252#M14406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sounds like you need to learn Python...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have any specific examples of VBA code you need to convert to Python?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 15:05:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187252#M14406</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-01-14T15:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187253#M14407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, thank you very much, for example, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EXPAND([Streams_rr2m],10,LIST,1.2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;INT([Ran_Ras] * 10) + 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[Angles] * 57.296&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so if you have any information about typing expressions by python plz help me, precisely (Raster Calculator operators and functions)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;thank you very much again for interesting and following my post&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 16:50:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187253#M14407</guid>
      <dc:creator>MustafaELHalwagy</dc:creator>
      <dc:date>2011-01-14T16:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187254#M14408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you using ArcGIS v10 or v9.3? In v10 there is a new raster calculator syntax that I am not up and running with yet. However, even in v10 you can still use the good old MapAlgebra syntax via Python. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#EXPAND([Streams_rr2m],10,LIST,1.2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inputGrd = r"C:\temp\input"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;somaExp = "expand(" + inputGrd + ", 10, 'LIST', 1.2)"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputGrd = r"C:\temp\output"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SingleOutputMapAlgebra_sa(somaExp, outputGrd, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#INT([Ran_Ras] * 10) + 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inputGrd = r"C:\temp\input"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;somaExp = "int(" + inputGrd + " * 10 + 1)"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputGrd = r"C:\temp\output"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SingleOutputMapAlgebra_sa(somaExp, outputGrd, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#[Angles] * 57.296&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inputGrd = r"C:\temp\input"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;somaExp = inputGrd + " * 57.296"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputGrd = r"C:\temp\output"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SingleOutputMapAlgebra_sa(somaExp, outputGrd, "")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 17:18:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187254#M14408</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-01-14T17:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187255#M14409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have ArcGis 10,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;i have tried to apply this syntax ("expand(" + inputGrd + ", 10, 'LIST', 1.2)"), but i have the same error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="&amp;lt;/span&amp;gt;&amp;lt;a" target="_blank"&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;IMG src="http://www1.mediafire.com/imgbnc.php/154c79e6a5eb5d3d0ac345ffbec8210f2a01004cc45237c9dc41224864f5bde06g.jpg" /&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="&amp;lt;/span&amp;gt;&amp;lt;a" target="_blank"&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;IMG src="http://www0.mediafire.com/imgbnc.php/068e259e3eb2ef28d25fefbe601487e8f70bf2b6d68a35014d23f9b30ea07bc46g.jpg" /&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thank you&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 17:56:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187255#M14409</guid>
      <dc:creator>MustafaELHalwagy</dc:creator>
      <dc:date>2011-01-14T17:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187256#M14410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is a python crash course for the field calculator (assuming ArcGIS 10):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;First of all python is just as easy as VB (if not easier). It's just a different language, so the syntax is not identical to VB. That means that you can't write VB in python, just as you can't write C++, Perl or C# in python, so yes you need to learn a little python to write python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Second: The field calculator is actually extending the python language with the notation of "fields names" just as it did with VB. In VB field calculator you quote field names with sqaure brackets: [field_name]. In python you do the same, but with exclamation marks instead: !field_name!. That is because square brackets already have a different meaning in python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Third: String formatting in python is much more powerful than i VB, and also very different from VB. To format a string in python one creates a "format string" and then use the format operator:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
"This is a %s with the integer %d and the float %.4f" % ('format string', 42, 3.14159265)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Fourth: To pick substring from a string, one use index and slicing:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
"mississippi"[0] # -&amp;gt; "m"
"mississippi"[:4] # -&amp;gt; "miss" # End at the 4th character
"mississippi"[-4:] # -&amp;gt;"ippi" # Start is 4th from the right
"mississippi"[::-1] # -&amp;gt; "ippississim" # Stepping backwards
"mississippi"[1::3] # -&amp;gt; "iiii" # Start at 1, and step 3
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;So for some field calculator examples:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To copy the contents from one field to another, just quote the source field name in exclamation marks:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
!source_field!
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;To copy and format floating point numbers to a text field, use a format string:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
"%.3f" % !source_float_field!
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;To fill a column with the time of day, formatted in 12 hour format:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;First check the "Show codeblock" checkbox, then in the Pre-Logic Script Code box enter the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import datetime
t = datetime.datetime.now()
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Then in the calc field code box below enter the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
t.strftime('%I:%M:%S %p) # See python help for strftime for details
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Given a float field with POSIX timestamps (seconds since epoch). To convert that to a date and time string in ISO format (2010-01-15 06:43:12):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in the pre-logic box enter:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import datetime
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;and in the calc window enter:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
datetime.datetime.fromtimestamp(!time_stamp_field!).strftime('%Y-%m-%d %H:%M:%S')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try these examples out and then come back with more specific questions about the Calculate Field functionallity. Also keep in mind that some people here (me included), might not be fluent in VB, so examples of what you expect specific VB code snippets to do is helpful.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:28:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187256#M14410</guid>
      <dc:creator>NiklasNorrthon</dc:creator>
      <dc:date>2021-12-11T09:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187257#M14411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Here is a python crash course for the field calculator (assuming ArcGIS 10):&lt;BR /&gt;&lt;BR /&gt;First of all python is just as easy as VB (if not easier). It's just a different language, so the syntax is not identical to VB. That means that you can't write VB in python, just as you can't write C++, Perl or C# in python, so yes you need to learn a little python to write python.&lt;BR /&gt;&lt;BR /&gt;Second: The field calculator is actually extending the python language with the notation of "fields names" just as it did with VB. In VB field calculator you quote field names with sqaure brackets: [field_name]. In python you do the same, but with exclamation marks instead: !field_name!. That is because square brackets already have a different meaning in python.&lt;BR /&gt;&lt;BR /&gt;Third: String formatting in python is much more powerful than i VB, and also very different from VB. To format a string in python one creates a "format string" and then use the format operator:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
"This is a %s with the integer %d and the float %.4f" % ('format string', 42, 3.14159265)&lt;/PRE&gt;&lt;BR /&gt;Fourth: To pick substring from a string, one use index and slicing:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
"mississippi"[0] # -&amp;gt; "m"
"mississippi"[:4] # -&amp;gt; "miss" # End at the 4th character
"mississippi"[-4:] # -&amp;gt;"ippi" # Start is 4th from the right
"mississippi"[::-1] # -&amp;gt; "ippississim" # Stepping backwards
"mississippi"[1::3] # -&amp;gt; "iiii" # Start at 1, and step 3
&lt;/PRE&gt;&lt;BR /&gt;So for some field calculator examples:&lt;BR /&gt;To copy the contents from one field to another, just quote the source field name in exclamation marks:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
!source_field!
&lt;/PRE&gt;&lt;BR /&gt;To copy and format floating point numbers to a text field, use a format string:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
"%.3f" % !source_float_field!
&lt;/PRE&gt;&lt;BR /&gt;To fill a column with the time of day, formatted in 12 hour format:&lt;BR /&gt;First check the "Show codeblock" checkbox, then in the Pre-Logic Script Code box enter the following:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import datetime
t = datetime.datetime.now()
&lt;/PRE&gt;&lt;BR /&gt;Then in the calc field code box below enter the following:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
t.strftime('%I:%M:%S %p) # See python help for strftime for details
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Given a float field with POSIX timestamps (seconds since epoch). To convert that to a date and time string in ISO format (2010-01-15 06:43:12):&lt;BR /&gt;in the pre-logic box enter:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import datetime
&lt;/PRE&gt;&lt;BR /&gt;and in the calc window enter:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
datetime.datetime.fromtimestamp(!time_stamp_field!).strftime('%Y-%m-%d %H:%M:%S')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Try these examples out and then come back with more specific questions about the Calculate Field functionallity. Also keep in mind that some people here (me included), might not be fluent in VB, so examples of what you expect specific VB code snippets to do is helpful.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank u very much niklas.norrthon, i had tried to write the syntax again by following ur post,put the same problem had appeared again, so if you want to try this by urself, and what can i do with this expression &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for example&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Streams_rr2m],10,LIST,1.2)(vb)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;thank you very much again&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:28:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187257#M14411</guid>
      <dc:creator>MustafaELHalwagy</dc:creator>
      <dc:date>2021-12-11T09:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187258#M14412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't know what your VB function is supposed to do. If you can give an example of unformatted data, and how you want it formatted I might be able to help you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jan 2011 14:22:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187258#M14412</guid>
      <dc:creator>NiklasNorrthon</dc:creator>
      <dc:date>2011-01-15T14:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187259#M14413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, i will say you the story from the start, i want to make a (tip) to make a buffering raster by spatial analyst tool, so to make this, we must be open (Raster Calc) and then type this syntax in the field raster calc: EXPAND ([Streams_rr2m],10,LIST,1.2 ) it was made by vb, so tha spatial analyst command, EXPAND: it mean that fatten up the zones, which is reputed to be the raster equivalent of the vector produce BUFFER. so i&amp;nbsp; just need only, if this proper syntax in Python field, i do not know this exactly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;thank you&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jan 2011 20:03:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187259#M14413</guid>
      <dc:creator>MustafaELHalwagy</dc:creator>
      <dc:date>2011-01-15T20:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187260#M14414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;vb function is: EXPAND ([Streams_rr2m],10,LIST,1.2 )&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jan 2011 22:17:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187260#M14414</guid>
      <dc:creator>MustafaELHalwagy</dc:creator>
      <dc:date>2011-01-15T22:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187261#M14415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mustafa needs help with the new map algebra syntax (v10 syntax). I haven't gotten there yet, but... Here's the intro to the help topic though: &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/What_is_Map_Algebra/00p600000002000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/What_is_Map_Algebra/00p600000002000000/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jan 2011 23:01:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187261#M14415</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-01-15T23:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187262#M14416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Jan 2011 17:07:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187262#M14416</guid>
      <dc:creator>MustafaELHalwagy</dc:creator>
      <dc:date>2011-01-16T17:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187263#M14417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am having a similar issue of converting a VB code block to a equivalent python code block for use in the Calculate Field tool. I used the following VB code with NewString as the expression in Modelbuilder and it works fine; however, I want to run the Calculate Field as a Python Script so seems like I need to convert it. The objective is to get the three digit date from the time field (i.e 000 to 366) and then assign it the appropriate image date based on where it fits in the select case.&amp;nbsp; So in this case the field calculated is ImgDate and ImgDate = NewString from expression below&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dim NewString as string
Select case (Right("00" + CStr(DatePart("y", [Date_Time])), 3))
case 1 to 16
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "1"
case 17 to&amp;nbsp; 32
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "17"
case 33 to 48
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "33"
case 49 to&amp;nbsp; 64
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "49"
case 65 to 80
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "65"
case 81 to&amp;nbsp; 96
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "81"
case 97 to 112
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "97"
case 113 to&amp;nbsp; 128
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "113"
case 129 to 144
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "129"
case 145 to&amp;nbsp; 160
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "145"
case 161 to 176
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "161"
case 177 to&amp;nbsp; 192
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "177"
case 193 to 208
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "193"
case 209 to&amp;nbsp; 224
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "209"
case 225 to 240
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "225"
case 241 to&amp;nbsp; 256
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "241"
case 257 to&amp;nbsp; 272
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "257"
case 273 to 288
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "273"
case 289 to&amp;nbsp; 304
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "289"
case 305 to 320
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "305"
case 321 to&amp;nbsp; 336
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "321"
case 337 to 352
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "337"
case 353 to&amp;nbsp; 367
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "353"
case else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NewString = "Error"
end select&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I've got the select case statements figured out, but can't seem to figure out how to get the appropriate three digit date value as a string from a DateTime Field&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried this in the code block of Modelbuilder but it doesn't work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;NewString =&amp;nbsp; (rstrip("00" + Str(DatePart("y", !Date_Time!)), 3))

def Calc(NewString):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if NewString &amp;gt;= 1 or NewString &amp;lt;= 16:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif NewString &amp;gt;= 17 or NewString &amp;lt;=32:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 17
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif NewString &amp;gt;= 33 or NewString &amp;lt;=48:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 33
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0 &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I"m also having trouble converting this VB line that takes the image date determined in the code above and adds the year to it and .tif extension to the end (e.g 2006D032.tif) as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;CStr(DatePart("yyyy", [Date_Time])) + "D" +&amp;nbsp; Right("00" + CStr([ImgDate]), 3) + ".tif"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated. Thanks in advance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:28:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187263#M14417</guid>
      <dc:creator>KarlZimmer</dc:creator>
      <dc:date>2021-12-11T09:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187264#M14418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As mentioned above you can use the datetime module to convert your dates to the day of the year.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The codeblock below demonstrates how to do it. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first line splits the date into a Python list containing the day, month, and year. Note the map function runs the int function on each part to convert them from strings to integers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The second line creates a date object using the Python list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The third line converts the date to the day of the year.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import datetime
def Calc(strDate):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lstDate = map(int, strDate.split("/")) # create list of date integers&amp;nbsp; D(D), M(M), YYYY
&amp;nbsp;&amp;nbsp;&amp;nbsp; objDate = datetime.date(lstDate[2], lstDate[1], lstDate[0]) # create date object
&amp;nbsp;&amp;nbsp;&amp;nbsp; intDay = int(objDate.strftime("%j")) # integer day of the year
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(1, 366, 16):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if intDay &amp;gt;= i and intDay &amp;lt; i+16:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return i
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(Use Calc(!Date_Time!) as the EXPRESSION.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Creating a string such as "2006D032.tif" is simply a matter of concatenating the parts of the date object using stftime formatting (dig around here &lt;/SPAN&gt;&lt;A href="http://docs.python.org/library/datetime.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/library/datetime.html&lt;/A&gt;&lt;SPAN&gt; for more info regarding format codes).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

strTif = objDate.strftime("%Y") + "D" + objDate.strftime("%j") + ".tif" 

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:28:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187264#M14418</guid>
      <dc:creator>BradPosthumus</dc:creator>
      <dc:date>2021-12-11T09:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187265#M14419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Brad,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the reply.&amp;nbsp; I believe what you have suggested is exactly what I need and is much more efficient then my current vb code! However, I am still struggling with the syntax and getting the Calculate Field tool to work properly. I keep getting the following error. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000539: Error running expression: Calc("1/29/2007") &amp;lt;type 'exceptions.NameError'&amp;gt;: global name 'objDate' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Calculate Field (3))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've attached screen shots of the parameters I entered in the Calculate Field tool.&amp;nbsp; I looked through the link you sent, but still can't seem to figure out the error. My field in the attribute table is Named Date_Time and is Type Date. The date is formated&amp;nbsp; M/DD/YYYY (1/29/2007).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any futher help would be greatly appreciated! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Karl&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jan 2011 03:12:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187265#M14419</guid>
      <dc:creator>KarlZimmer</dc:creator>
      <dc:date>2011-01-26T03:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187266#M14420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For the second script, you need to (1) create the date object, (2) pass the ImgDate attribute as a parameter to the Calc function, and (3) return the result of the function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See if this works, using Calc(!Date_Time!, !ImgDate!) as the expression:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import datetime
def Calc(strDate, strImageDate):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lstDate = map(int, strDate.split("/")) # create list of date integers&amp;nbsp; D(D), M(M), YYYY
&amp;nbsp;&amp;nbsp;&amp;nbsp; objDate = datetime.date(lstDate[2], lstDate[1], lstDate[0]) # create date object
&amp;nbsp;&amp;nbsp;&amp;nbsp; strTif = r"J:\GEOG683\HED_NDVI_GEO" + r"\Montana_Canada_NDVI_A" + objDate.strftime("%Y") + "D" + strImageDate + ".tif"
&amp;nbsp;&amp;nbsp;&amp;nbsp; return strTif
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alternatively, you can shorten this quite a bit. Since you just need the year in this script you could directly split it out from Date_Time attribute:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import datetime
def Calc(strDate, strImageDate):
&amp;nbsp;&amp;nbsp;&amp;nbsp; return r"J:\GEOG683\HED_NDVI_GEO" + r"\Montana_Canada_NDVI_A" + strDate.split("/")[2] + "D" + strImageDate + ".tif"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:28:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187266#M14420</guid>
      <dc:creator>BradPosthumus</dc:creator>
      <dc:date>2021-12-11T09:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187267#M14421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Brad,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you so much for your patience and assistance. However, I am still getting an error when I run the Calculate Field. However, now my error is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000539: Error running expression: Calc("6/16/2006") &amp;lt;type 'exceptions.ValueError'&amp;gt;: month must be in 1..12&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Calculate Field (3)).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think this must mean my Date_Time field isn't in the correct format. Reading the ArcGIS help online it mentions that shapefiles and coverages store Dates differently as it only stores dates and not time. In anycase my dataset is a shapefile and I'm working in 9.3.1 if that makes a difference. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I apologize for not figuring this out myself, but I've having some trouble understanding the details of the code as I'm new to Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for you help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jan 2011 13:30:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187267#M14421</guid>
      <dc:creator>KarlZimmer</dc:creator>
      <dc:date>2011-01-26T13:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Code in python the equivalent of the VB Format function</title>
      <link>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187268#M14422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Brad,&lt;BR /&gt;&lt;BR /&gt;Thank you so much for your patience and assistance. However, I am still getting an error when I run the Calculate Field. However, now my error is:&lt;BR /&gt;&lt;BR /&gt;ERROR 000539: Error running expression: Calc("6/16/2006") &amp;lt;type 'exceptions.ValueError'&amp;gt;: month must be in 1..12&lt;BR /&gt;Failed to execute (Calculate Field (3)).&lt;BR /&gt;&lt;BR /&gt;I think this must mean my Date_Time field isn't in the correct format. Reading the ArcGIS help online it mentions that shapefiles and coverages store Dates differently as it only stores dates and not time. In anycase my dataset is a shapefile and I'm working in 9.3.1 if that makes a difference. &lt;BR /&gt;&lt;BR /&gt;I apologize for not figuring this out myself, but I've having some trouble understanding the details of the code as I'm new to Python.&lt;BR /&gt;&lt;BR /&gt;Thanks again for you help!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let's start with this line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lstDate = map(int, strDate.split("/")) # create list of date integers&amp;nbsp; D(D), M(M), YYYY&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(note that comments are preceded by #, so anything following # is ignored)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is actually two commands joined as one: the "map" function and the "split" string method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Say you have a date of "6/16/2006". The string method&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;strDate.split("/") &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;creates a Python list by splitting the string at the forward slash, with a result of ["6", "16", "2006"]. So now Python interprets the line as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lstDate = map(int, ["6", "16", "2006"]) &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The map function simply says "take each element in the list (second parameter) and pass it into the function defined in the first parameter". In this case, each element is passed into the int() function, converting the strings in the list to integers. So now Python interprets the line as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lstDate = [6, 16, 2006]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To access each element in the list you append an index number in square brackets to the list variable name. The index numbering starts with 0, so you can extract each value like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
lstDate[0] = 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # month
lstDate[1] = 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # date
lstDate[2] = 2006&amp;nbsp;&amp;nbsp; # year&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now jump into this line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;objDate = datetime.date(lstDate[2], lstDate[1], lstDate[0]) # create date object&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The date object is created by passing three parameters, as integers, to the datetime.date method in the following order:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;datetime.date(&amp;lt;year&amp;gt;, &amp;lt;month&amp;gt;, &amp;lt;date&amp;gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The date format in my data was DD/MM/YYYY, so lstDate[0] was day, lstDate[1], was month, and lstDate[2] was year. Therefore, the parameters are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;datetime.date(lstDate[2], lstDate[1], lstDate[0])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your data (and I didn't notice before my last post) is MM/DD/YYYY. Therefore, you simply need to change the order of the parameters to fix the error. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;objDate = datetime.date(lstDate[2], lstDate[0], lstDate[1]) # create date object&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:28:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-in-python-the-equivalent-of-the-vb-format/m-p/187268#M14422</guid>
      <dc:creator>BradPosthumus</dc:creator>
      <dc:date>2021-12-11T09:28:34Z</dc:date>
    </item>
  </channel>
</rss>

