1

In order to write a script calculating the current stand of a bank account, I would need to write a function finding the income and outcome events between the initiated date and the current date.

Using datetime in Python it is possible to find the number of days that have passed between two dates with datetime.timedelta, however for any transaction that occurs monthly or yearly, I would need something to find also the number of months and years between, taking into account the different lengths of them.

Is there a way of finding the number of "events" (i.e. specific dates) between to input dates using datetime in Python?

For example: Transaction t1 occurs every day 2 of each month. Transaction t2 occur every 14 days starting on January first. Given two input dates July 03 and August 29, the function finds how many time t1 and t2 have happened (and uses this to compute the final value)

hirschme
  • 774
  • 2
  • 11
  • 40

1 Answers1

0

This should give a difference in days:

from datetime import date, datetime

        day_delta = (d_i[ith] - d_o).days

If the day of interest is in between bounding days, then the differences should be positive and negative. The product of the deltas will be negative.

delta_beg = (beg_date - date_of_interest).days
delta_end = (end_date - date_of_interest).days
if delta_beg * delta_end < 0.0:
    print "date is in between"
R. Wayne
  • 417
  • 1
  • 9
  • 17
  • Yes, I know how to get the number of days in between (wrote that unclearly in the question), but that does not allow to find if a specific date is between those days – hirschme Nov 12 '17 at 03:05
  • This link has some methods you might like better: https://stackoverflow.com/questions/5464410/how-to-tell-if-a-date-is-between-two-other-dates-in-python – R. Wayne Nov 12 '17 at 03:16