Nico Pérez
Nico Pérez

Reputation: 33

Convert a timedelta to int

I would like to convert timedelta to int so that I can do math with it but I keep getting this error:

numpy.core._exceptions._UFuncBinaryResolutionError: ufunc 'true_divide' cannot use operands with types dtype('O') and dtype('<m8[D]')

here is the code:

zeit = datetime(2023, 1, 1)
    today = datetime.now()

    new_date = zeit-today

days_int=(new_date / np.timedelta64(1, 'D')).astype(int)

Upvotes: 3

Views: 9558

Answers (1)

shamnad sherief
shamnad sherief

Reputation: 638

if u want to convert only days in int then use new_date.days

Upvotes: 2

Related Questions