# Python code to sum between two dates and times

**URL:** <https://discuss.python.org/t/python-code-to-sum-between-two-dates-and-times/20007>\
**Category:** Python Help\
**Created:** [October 15, 2022, 1:32pm UTC](https://discuss.python.org/t/python-code-to-sum-between-two-dates-and-times/20007 "2022-10-15T13:32:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dennisdr22](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@dennisdr22](https://discuss.python.org/u/dennisdr22)\
**Post date:** [October 15, 2022, 1:32pm UTC](https://discuss.python.org/t/python-code-to-sum-between-two-dates-and-times/20007/1 "2022-10-15T13:32:10Z")

</div>

If I have an excel file with the dates and times how do I create a code that will sum the number between certain dates and times?

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [October 15, 2022, 8:40pm UTC](https://discuss.python.org/t/python-code-to-sum-between-two-dates-and-times/20007/2 "2022-10-15T20:40:20Z")

</div>

I would guess:

- read the Excel file; I usually use `openpyxl` for this, but `pandas`  
can read them too and there are other packages
- get the “sheet” containing the dta you want, scan the rows to get your  
pairs of date/times according to your criteria
- subtract the pairs
- sum the differences?

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)
