Search code examples
pythonpython-datetimetimedelta

Python timedelta result to integer number


Sorry I'm beginner, how do you make int the the result of timedelta because it gives the format with "d" and utc, sorry for my bad English

          y, m, d = map(int, input('FIRST DATE: ').split(','))
          f_date = date(y, m, d)
          y, m, d = map(int, input('SECOND DATE: ').split(','))
          l_date = date(y, m, d)
          delta = (l_date - f_date:%d)
        i1 = (p * r)
        i2 = (delta / 360)
        i = i1 * i2
        print(i)

Solution

  • A timedelta has three fields, days, seconds, and microseconds.

    So td.days * 86_400 + td.seconds + td.microseconds/1_000_000 gives you the length timedelta td in seconds.