<?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 Got Error when ran python - TypeError: can't compare datetime.datetime to datetime.date in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/got-error-when-ran-python-typeerror-can-t-compare/m-p/1261674#M66935</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Hello all,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I have ArcGIS Pro 3.0 and python 27. I am not expertise with code. Please see error and code below. It is working fine when using "&lt;STRONG&gt;processFilesAddedOnDate = datetime.strptime('01/01/2023', '%m/%d/%Y')&lt;/STRONG&gt;". But when I switched to "&lt;STRONG&gt;processFilesAddedOnDate = date.today()&lt;/STRONG&gt;", I got an error message. I am not sure what to do. Please kindly assist. Thank you so much in advance.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ERROR MESSAGE&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;= RESTART: M:\ArcGIS\ArcGIS\Projects\EC\PROD2023.py&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Traceback (most recent call last):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;File "M:\ArcGIS\ArcGIS\Projects\EC\PROD2023.py", line 33, in &amp;lt;module&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;if datetime.fromtimestamp(os.path.getctime(os.path.join(root, f))) &amp;gt;= processFilesAddedOnDate:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;TypeError: can't compare datetime.datetime to datetime.date&lt;/FONT&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;PYTHON SCRIPT CODE&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import csv
import os
from datetime import date
from datetime import datetime

matchTableName = r"ElevationCertificatesAttachmentMatchTable.csv"
docFolder = r"Q:\2023\IMPORTED TO GIS"

matchField = "MatchID"
pathField = "Filename" 

#change this date to the disired value
#processFilesAddedOnDate = datetime.strptime('01/01/2023', '%m/%d/%Y')
processFilesAddedOnDate = date.today()

# iterate through each .pdf file in the directory and write a row to the table

       
for (root, dirs, files) in os.walk(docFolder):
    workingFolder = root
    matchTableNamePath = os.path.join(root, matchTableName)
    # create a new Match Table csv file
    if os.path.exists(matchTableNamePath):
        os.remove(matchTableNamePath)
    writer = csv.writer(open(matchTableNamePath, "w", newline=''), delimiter=",")
    # write a header row (the table will have two columns: ParcelID and Picture)
    writer.writerow([matchField, pathField, 'fullPath'])
    for f in files:
        
        if '.pdf' in f:
            #if datetime.strptime(os.path.getctime(os.path.join(root, f)),"%m/%d/%Y") &amp;gt;= processFilesAddedOnDate:
            if datetime.fromtimestamp(os.path.getctime(os.path.join(root, f))) &amp;gt;= processFilesAddedOnDate:
                
                #print(os.path.getctime(os.path.join(root, f)).strftime("%m/%d/%Y")+ '   ' + processFilesAddedOnDate.strftime("%m/%d/%Y"))
                fileNameToAddress = f.replace(".pdf", "")
                fileNameToAddress = fileNameToAddress.replace("  ", " ");
                fileNameToAddress = fileNameToAddress.replace("nw", "NW")
                try:
                    firstPartUntilNW = fileNameToAddress.split("NW")[0].strip().split(" ")
                    restAfterNW = fileNameToAddress.split("NW")[1].strip()
                    #print(firstPartUntilNW, len(firstPartUntilNW))
                    #print(restAfterNW)
                    fileNameToAddressWithNoPermitNumber = ""
                    if len(firstPartUntilNW) == 2:
                        fileNameToAddressWithNoPermitNumber = firstPartUntilNW[1]+" NW "+restAfterNW
                    if len(firstPartUntilNW)== 1:
                        fileNameToAddressWithNoPermitNumber = firstPartUntilNW[0]+" NW "+restAfterNW
                    #print(fileNameToAddressWithNoPermitNumber)
                    writer.writerow((fileNameToAddressWithNoPermitNumber,f, os.path.join(root, f)))
                except:
                    continue
      
    del writer

    # Set the workspace environment and run add attachment
    arcpy.env.workspace = r'C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'

    arcpy.management.AddAttachments('sde.123.test', 'ADDR', matchTableNamePath, "MatchID", "Filename", workingFolder)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Feb 2023 21:26:48 GMT</pubDate>
    <dc:creator>AlexP_</dc:creator>
    <dc:date>2023-02-24T21:26:48Z</dc:date>
    <item>
      <title>Got Error when ran python - TypeError: can't compare datetime.datetime to datetime.date</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-ran-python-typeerror-can-t-compare/m-p/1261674#M66935</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Hello all,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I have ArcGIS Pro 3.0 and python 27. I am not expertise with code. Please see error and code below. It is working fine when using "&lt;STRONG&gt;processFilesAddedOnDate = datetime.strptime('01/01/2023', '%m/%d/%Y')&lt;/STRONG&gt;". But when I switched to "&lt;STRONG&gt;processFilesAddedOnDate = date.today()&lt;/STRONG&gt;", I got an error message. I am not sure what to do. Please kindly assist. Thank you so much in advance.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ERROR MESSAGE&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;= RESTART: M:\ArcGIS\ArcGIS\Projects\EC\PROD2023.py&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Traceback (most recent call last):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;File "M:\ArcGIS\ArcGIS\Projects\EC\PROD2023.py", line 33, in &amp;lt;module&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;if datetime.fromtimestamp(os.path.getctime(os.path.join(root, f))) &amp;gt;= processFilesAddedOnDate:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;TypeError: can't compare datetime.datetime to datetime.date&lt;/FONT&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;PYTHON SCRIPT CODE&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import csv
import os
from datetime import date
from datetime import datetime

matchTableName = r"ElevationCertificatesAttachmentMatchTable.csv"
docFolder = r"Q:\2023\IMPORTED TO GIS"

matchField = "MatchID"
pathField = "Filename" 

#change this date to the disired value
#processFilesAddedOnDate = datetime.strptime('01/01/2023', '%m/%d/%Y')
processFilesAddedOnDate = date.today()

# iterate through each .pdf file in the directory and write a row to the table

       
for (root, dirs, files) in os.walk(docFolder):
    workingFolder = root
    matchTableNamePath = os.path.join(root, matchTableName)
    # create a new Match Table csv file
    if os.path.exists(matchTableNamePath):
        os.remove(matchTableNamePath)
    writer = csv.writer(open(matchTableNamePath, "w", newline=''), delimiter=",")
    # write a header row (the table will have two columns: ParcelID and Picture)
    writer.writerow([matchField, pathField, 'fullPath'])
    for f in files:
        
        if '.pdf' in f:
            #if datetime.strptime(os.path.getctime(os.path.join(root, f)),"%m/%d/%Y") &amp;gt;= processFilesAddedOnDate:
            if datetime.fromtimestamp(os.path.getctime(os.path.join(root, f))) &amp;gt;= processFilesAddedOnDate:
                
                #print(os.path.getctime(os.path.join(root, f)).strftime("%m/%d/%Y")+ '   ' + processFilesAddedOnDate.strftime("%m/%d/%Y"))
                fileNameToAddress = f.replace(".pdf", "")
                fileNameToAddress = fileNameToAddress.replace("  ", " ");
                fileNameToAddress = fileNameToAddress.replace("nw", "NW")
                try:
                    firstPartUntilNW = fileNameToAddress.split("NW")[0].strip().split(" ")
                    restAfterNW = fileNameToAddress.split("NW")[1].strip()
                    #print(firstPartUntilNW, len(firstPartUntilNW))
                    #print(restAfterNW)
                    fileNameToAddressWithNoPermitNumber = ""
                    if len(firstPartUntilNW) == 2:
                        fileNameToAddressWithNoPermitNumber = firstPartUntilNW[1]+" NW "+restAfterNW
                    if len(firstPartUntilNW)== 1:
                        fileNameToAddressWithNoPermitNumber = firstPartUntilNW[0]+" NW "+restAfterNW
                    #print(fileNameToAddressWithNoPermitNumber)
                    writer.writerow((fileNameToAddressWithNoPermitNumber,f, os.path.join(root, f)))
                except:
                    continue
      
    del writer

    # Set the workspace environment and run add attachment
    arcpy.env.workspace = r'C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'

    arcpy.management.AddAttachments('sde.123.test', 'ADDR', matchTableNamePath, "MatchID", "Filename", workingFolder)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 21:26:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-ran-python-typeerror-can-t-compare/m-p/1261674#M66935</guid>
      <dc:creator>AlexP_</dc:creator>
      <dc:date>2023-02-24T21:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when ran python - TypeError: can't compare datetime.datetime to datetime.date</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-ran-python-typeerror-can-t-compare/m-p/1261787#M66940</link>
      <description>&lt;P&gt;Well you're comparing a date to a datetime.&lt;BR /&gt;2023-02-01 00:00:00 &amp;gt;=&amp;nbsp;2023-01-01 00:00:00 - True&lt;BR /&gt;2023-02-01 00:00:00 &amp;gt;=&amp;nbsp;2023-01-01 - nope&lt;BR /&gt;&lt;BR /&gt;Simplest would be to convert your datetime to a date or more efficient to get the date from the timestamp straightaway.&lt;BR /&gt;As I'm a simple person, psb:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if (datetime.fromtimestamp(os.path.getctime(os.path.join(root, f)))).date() &amp;gt;= processFilesAddedOnDate:&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2023 17:28:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-ran-python-typeerror-can-t-compare/m-p/1261787#M66940</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2023-02-25T17:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Got Error when ran python - TypeError: can't compare datetime.datetime to datetime.date</title>
      <link>https://community.esri.com/t5/python-questions/got-error-when-ran-python-typeerror-can-t-compare/m-p/1261802#M66943</link>
      <description>&lt;P&gt;&lt;SPAN&gt;This&lt;/SPAN&gt;&lt;SPAN&gt; error&lt;/SPAN&gt;&lt;SPAN&gt; typically&lt;/SPAN&gt;&lt;SPAN&gt; occurs&lt;/SPAN&gt;&lt;SPAN&gt; when&lt;/SPAN&gt;&lt;SPAN&gt; attempting&lt;/SPAN&gt;&lt;SPAN&gt; to&lt;/SPAN&gt;&lt;SPAN&gt; compare&lt;/SPAN&gt;&lt;SPAN&gt; two&lt;/SPAN&gt;&lt;SPAN&gt; different&lt;/SPAN&gt;&lt;SPAN&gt; types&lt;/SPAN&gt;&lt;SPAN&gt; of&lt;/SPAN&gt;&lt;SPAN&gt; objects&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt; such&lt;/SPAN&gt;&lt;SPAN&gt; as&lt;/SPAN&gt;&lt;SPAN&gt; an&lt;/SPAN&gt;&lt;SPAN&gt; integer&lt;/SPAN&gt;&lt;SPAN&gt; and&lt;/SPAN&gt;&lt;SPAN&gt; a&lt;/SPAN&gt;&lt;SPAN&gt; string&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt; To&lt;/SPAN&gt;&lt;SPAN&gt; resolve&lt;/SPAN&gt;&lt;SPAN&gt; this&lt;/SPAN&gt;&lt;SPAN&gt; issue&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt; convert&lt;/SPAN&gt;&lt;SPAN&gt; one&lt;/SPAN&gt;&lt;SPAN&gt; of&lt;/SPAN&gt;&lt;SPAN&gt; the&lt;/SPAN&gt;&lt;SPAN&gt; objects&lt;/SPAN&gt;&lt;SPAN&gt; to&lt;/SPAN&gt;&lt;SPAN&gt; the&lt;/SPAN&gt;&lt;SPAN&gt; same&lt;/SPAN&gt;&lt;SPAN&gt; type&lt;/SPAN&gt;&lt;SPAN&gt; as&lt;/SPAN&gt;&lt;SPAN&gt; the&lt;/SPAN&gt;&lt;SPAN&gt; other&lt;/SPAN&gt;&lt;SPAN&gt; object&lt;/SPAN&gt;&lt;SPAN&gt; before&lt;/SPAN&gt;&lt;SPAN&gt; attempting&lt;/SPAN&gt;&lt;SPAN&gt; to&lt;/SPAN&gt;&lt;SPAN&gt; compare&lt;/SPAN&gt;&lt;SPAN&gt; them&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt; For&lt;/SPAN&gt;&lt;SPAN&gt; example&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt; if&lt;/SPAN&gt;&lt;SPAN&gt; one&lt;/SPAN&gt;&lt;SPAN&gt; object&lt;/SPAN&gt;&lt;SPAN&gt; is&lt;/SPAN&gt;&lt;SPAN&gt; an&lt;/SPAN&gt;&lt;SPAN&gt; integer&lt;/SPAN&gt;&lt;SPAN&gt; and&lt;/SPAN&gt;&lt;SPAN&gt; the&lt;/SPAN&gt;&lt;SPAN&gt; other&lt;/SPAN&gt;&lt;SPAN&gt; is&lt;/SPAN&gt;&lt;SPAN&gt; a&lt;/SPAN&gt;&lt;SPAN&gt; string&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt; you&lt;/SPAN&gt;&lt;SPAN&gt; can&lt;/SPAN&gt;&lt;SPAN&gt; convert&lt;/SPAN&gt;&lt;SPAN&gt; the&lt;/SPAN&gt;&lt;SPAN&gt; string&lt;/SPAN&gt;&lt;SPAN&gt; to&lt;/SPAN&gt;&lt;SPAN&gt; an&lt;/SPAN&gt;&lt;SPAN&gt; integer&lt;/SPAN&gt;&lt;SPAN&gt; using&lt;/SPAN&gt;&lt;SPAN&gt; the&lt;/SPAN&gt;&lt;SPAN&gt; int&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;SPAN&gt; function&lt;/SPAN&gt;&lt;SPAN&gt; before&lt;/SPAN&gt;&lt;SPAN&gt; attempting&lt;/SPAN&gt;&lt;SPAN&gt; to&lt;/SPAN&gt;&lt;SPAN&gt; compare&lt;/SPAN&gt;&lt;SPAN&gt; them&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2023 19:43:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/got-error-when-ran-python-typeerror-can-t-compare/m-p/1261802#M66943</guid>
      <dc:creator>MeGhanMWilliom</dc:creator>
      <dc:date>2023-02-25T19:43:20Z</dc:date>
    </item>
  </channel>
</rss>

