-2

I have 2 dates I want the no of days between the 2 dates how to retrieve that

expiry_date = details['expires']
today = date.today().strftime("%d/%m/%Y")

For example

28/11/2021
29/11/2021
no.of.days=1
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Abin M
  • 23
  • 2
  • [previously asked question](https://stackoverflow.com/questions/151199/how-to-calculate-number-of-days-between-two-given-dates) > click on the link – U-33 Nov 28 '21 at 05:38
  • Does this answer your question? [How to calculate number of days between two given dates](https://stackoverflow.com/questions/151199/how-to-calculate-number-of-days-between-two-given-dates) – FObersteiner Nov 29 '21 at 08:23

2 Answers2

1

If you have two datetime objects, you can subtract them to get a timedelta.

diff = (datetime.datetime.strptime("29/11/2021", "%d/%m/%Y") - 
        datetime.datetime.strptime("28/11/2021", "%d/%m/%Y"))

You can then convert to days:

diff.total_seconds() / 86400.
Addlestrop
  • 166
  • 3
0

Search for the answer yourself first, then ask if you can't find anything.

How to calculate number of days between two given dates

Use this

Craze XD
  • 110
  • 8