code: def delta(d1, d2, opt='d'):
      
      delta = 0
  
      if opt == 'm':
          while True:
              mdays = monthrange(d1.year, d1.month)[1]
              d1 += timedelta(days=mdays)
              if d1 <= d2:
                  delta += 1
              else:
                  break
      else:
          delta = (d2 - d1).days
  
      return delta
docs: Compute difference between given 2 dates in month/day.