<?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: Calculate date difference in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687432#M53210</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks to both of you!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Nov 2013 18:24:43 GMT</pubDate>
    <dc:creator>ErnestoCarreras3</dc:creator>
    <dc:date>2013-11-20T18:24:43Z</dc:date>
    <item>
      <title>Calculate date difference</title>
      <link>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687427#M53205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to calculate the difference between two dates in days. I need it to work within the Model Builder since these are models that need to be published later as a GP service. I have two fields, one with the Inspection date and the other with the Current date. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Something similar to the below VBscript:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;DateDiff("d", [date_field], Now())&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any advice will be appreciated. Thanks in advanced.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Nov 2013 18:51:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687427#M53205</guid>
      <dc:creator>ErnestoCarreras3</dc:creator>
      <dc:date>2013-11-19T18:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date difference</title>
      <link>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687428#M53206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can do that with the 'datetime' module:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/release/2.6.8/library/datetime.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/release/2.6.8/library/datetime.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import datetime
date1 = "1/1/1990"
date2 = "1/1/1980"
x = datetime.datetime.strptime(date1, "%m/%d/%Y")
y = datetime.datetime.strptime(date2, "%m/%d/%Y")
z = x - y
print z.days
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:54:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687428#M53206</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2021-12-12T04:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date difference</title>
      <link>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687429#M53207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure how to pull it off in model builder, but the Python datetime module works like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import datetime, arcpy
time1 = arcpy.da.SearchCursor(myFC, ["MY_DATE_FIELD"], "OBJECTID = 1").next()
time2 = datetime.datetime.now()
elapsedTime = time2 - time1
print "Total elapsed seconds: " + str(elapsedTime.totalSeconds)
print "Total elapsed days: " + str(elapsedTime.days)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:54:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687429#M53207</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T04:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date difference</title>
      <link>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687430#M53208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Woops - jinx - had that window open too long before I hit submit!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Nov 2013 22:08:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687430#M53208</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2013-11-19T22:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date difference</title>
      <link>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687431#M53209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great minds. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Nov 2013 22:31:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687431#M53209</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-11-19T22:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate date difference</title>
      <link>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687432#M53210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks to both of you!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Nov 2013 18:24:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-date-difference/m-p/687432#M53210</guid>
      <dc:creator>ErnestoCarreras3</dc:creator>
      <dc:date>2013-11-20T18:24:43Z</dc:date>
    </item>
  </channel>
</rss>

