title: Difference Python on Windows & Linux: datetime.datetime object has no attribute total_seconds
body: <p>A python script I developed in Linux works fine in Linux. It uses openpyxl to iterate over cells in an Excel-file, compares values to lists, and calculates total time spent by adding different timedelta objects (in total seconds). So far so good...</p>
  <p>But the script does not work on my Windows laptop I use for work. Installed is Python 3.8.5. The error I get is:</p>
  <pre><code>File &quot;Worktypes&quot;, line 54, in &lt;module&gt;
      ndcluren += int(f.total_seconds())
  AttributeError: 'datetime.datetime' object has no attribute 'total_seconds
  </code></pre>
  <p>The original code in the script is:</p>
  <pre><code>for j in range(6):
      facturen = 0
      decluren = 0
      ndcluren = 0
      resturen = 0
      
      for i in range(5,30):
          e = sheet2.cell(row = i, column = 1).value
          f = sheet2.cell(row = i, column = j+5).value
          if f:
              if e in fact:
                  facturen += int(f.total_seconds())
              elif e in decl:
                  decluren += int(f.total_seconds())
              elif e in ndcl:
                  ndcluren += int(f.total_seconds())
              else:
                  resturen += int(f.total_seconds())
      
      sheet4.cell(row = 2, column = j+3).value = facturen / 3600
      sheet4.cell(row = 3, column = j+3).value = decluren / 3600
      sheet4.cell(row = 4, column = j+3).value = ndcluren / 3600
      sheet4.cell(row = 5, column = j+3).value = resturen / 3600
  </code></pre>
  <p>What is somewhat surprising is that the script handles total_seconds() fine for the &quot;facturen&quot; and the &quot;decluren&quot;, but then fails for the ndcluren. This makes me think that the error is in the excel spreadsheet. But I cannot find anything strange or special. Changing the cell formatting also doesn't work.</p>
  <p>I already spent quite some hours on this. Indications from Google indicate that the script uses python2 instead of python3. But also after forcing python3 I get this error on Windows.</p>
  <p><strong>Solved</strong></p>
  <p>It turns out there are two issues at play.</p>
  <ol>
  <li><strong>First issue</strong>
  Excel registers duration times as a date. The cell displays 30:30 (30 hours and 30 minutes) but in the formula edit field in Excel this shows as &quot;1-1-1900  06:30:00&quot;. <a href="https://stackoverflow.com/questions/57874619/is-there-a-way-to-read-duration-type-field-from-excel-with-python-openpyxl">This question</a> gives the answer to this issue.</li>
  <li><strong>Second issue</strong>
  Some cells are recognized as datetime.time objects and some are recognized as datetime.datetime objects. In case of datetime.time objects the above solution does not work. I solved this by adding a date to the time object, and combine the date and time into a datetime object. The new script works as expected:</li>
  </ol>
  <pre><code>for j in range(6):
      facturen = 0
      decluren = 0
      ndcluren = 0
      resturen = 0
      
      for i in range(5,30):
          naam = sheet2.cell(row = i, column = 1).value
          cell = sheet2.cell(row = i, column = j+5)
          if cell.value:
              if isinstance(cell.value, datetime.time):
                  date = datetime.datetime.strptime('1899-12-31', '%Y-%m-%d').date()
                  s = datetime.datetime.combine(date, cell.value)
                  s = s-datetime.datetime(1899,12,31)
              else:
                  s = cell.value-datetime.datetime(1899,12,31)
              if naam in fact:
                  facturen += int(s.total_seconds())
              elif naam in decl:
                  decluren += int(s.total_seconds())
              elif naam in ndcl:
                  ndcluren += int(s.total_seconds())
              else:
                  resturen += int(s.total_seconds())
      
      sheet4.cell(row = 2, column = j+3).value = facturen / 3600
      sheet4.cell(row = 3, column = j+3).value = decluren / 3600
      sheet4.cell(row = 4, column = j+3).value = ndcluren / 3600
      sheet4.cell(row = 5, column = j+3).value = resturen / 3600
  </code></pre>
  <p>Still don't understand why in Windows needs extra lines of code, and python on Linux does not. But at least my issue is solved</p>