<?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 Compare File Save Date to a Specific Date in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591743#M46384</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am working on a python script to process mxd files.&amp;nbsp; I would like to only process mxd files that are newer than a specific date.&amp;nbsp; I have been able to compare time from now to a specific date but it keeps changing from day to day.&amp;nbsp; I would actually just like to compare the date saved to a specific date.&amp;nbsp; Is this possible with some type of date comparison (date &amp;gt; some date)?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Jan 2014 11:49:14 GMT</pubDate>
    <dc:creator>MichaelVolz</dc:creator>
    <dc:date>2014-01-28T11:49:14Z</dc:date>
    <item>
      <title>Compare File Save Date to a Specific Date</title>
      <link>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591743#M46384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am working on a python script to process mxd files.&amp;nbsp; I would like to only process mxd files that are newer than a specific date.&amp;nbsp; I have been able to compare time from now to a specific date but it keeps changing from day to day.&amp;nbsp; I would actually just like to compare the date saved to a specific date.&amp;nbsp; Is this possible with some type of date comparison (date &amp;gt; some date)?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 11:49:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591743#M46384</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2014-01-28T11:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Compare File Save Date to a Specific Date</title>
      <link>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591744#M46385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not knowing how you are getting the date that you are comparing to, for example if it is coded in the script or part of a tools input parameters, I'd say the easiest thing to do is get YYYY MM DD from the files and from your parameter. Then you could use the datetime library in python to do the comparisons. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import datetime
filedate = datetime.date(2014, 1, 27)
comparedate = datetime.date(2013, 12, 31)
if (filedate - comparedate).days &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Work on this file')
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Do nothing')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Would print&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; Work on this file
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The idea being that if you have a positive number of days between the file date and the compare date, then the file is 'new'. If the number of days is negative (or zero if the dates are the same), it is not new, so you wouldn't do anything.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Doug&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:25:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591744#M46385</guid>
      <dc:creator>DouglasSands</dc:creator>
      <dc:date>2021-12-12T01:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Compare File Save Date to a Specific Date</title>
      <link>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591745#M46386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you know if this would work as I don't want to process files older than say 7/1/2011 which was the last time I batch processed mxd files (no one has modified these files in ~ 2.5 years)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import datetime&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filedate = datetime.fromtimestamp(os.path.getmtime(rootpath + "/" + fName))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #filedate = datetime.date(2014, 1, 27)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;comparedate = datetime.now&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if (filedate - comparedate).days &amp;gt; 915: #915 is ~ 2.5 years&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Work on this file')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Do nothing')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem here is that the time frame keeps getting longer as time goes by.&amp;nbsp; I want to compare the date of the file against a specific date so the time frame does not keep changing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 14:53:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591745#M46386</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2014-01-28T14:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Compare File Save Date to a Specific Date</title>
      <link>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591746#M46387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having some difficulties getting something seemingly simple to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import datetime&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then_test = datetime.date(2011, 7, 2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print then_test&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;According to documentation this should print 2011-07-29&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but I am getting the error message descriptor 'date' requires a 'datetime.datetime' object but received a 'int'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyone know where I am going wrong here?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 18:23:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591746#M46387</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2014-01-28T18:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Compare File Save Date to a Specific Date</title>
      <link>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591747#M46388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To your first question about comparing to a specific date:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import datetime
filedate = datetime.fromtimestamp(os.path.getmtime(rootpath + "/" + fName)) #filedate = datetime.date(2014, 1, 27)
today = datetime.now
maxdate = datetime.date(2011, 7, 2)
#Only do work if the number of days since the last change is less than the number of days since a 'too long ago' date.
if (filedate - today).days &amp;lt; (filedate - maxdate).days:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Work on this file')
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Do nothing')

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I try and test the 2nd issue you bring up, I don't see the same result as you:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; import datetime&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; test = datetime.date(2011, 7, 2)&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; print test&lt;BR /&gt;2011-07-02&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; str(test)&lt;BR /&gt;'2011-07-02'&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; &lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It works for me as would be expected, so I don't have a good answer for you regarding that issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Doug&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:25:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591747#M46388</guid>
      <dc:creator>DouglasSands</dc:creator>
      <dc:date>2021-12-12T01:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Compare File Save Date to a Specific Date</title>
      <link>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591748#M46389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Doug:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the assistance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I finally found the issue which had to do with the import of the datetime module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had this statement at the top of my script&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;from datetime import datetime&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;maxdate = datetime.date(2011, 7, 2) throws the error I described previously&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had to change this statement to&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;maxdate = datetime(2011, 7, 2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and the error disappeared&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did not realize I was using the additional module reference at the beginning of the script&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jan 2014 14:52:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-file-save-date-to-a-specific-date/m-p/591748#M46389</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2014-01-30T14:52:49Z</dc:date>
    </item>
  </channel>
</rss>

