Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Number of 15 minutes intervals between two datetimes

from datetime import datetime, timedelta

now = datetime.now()
start = now + timedelta(minutes = 15)
finish = start + timedelta(minutes = 30)

How can I find the number of 15 minutes intervals exist between start and finish?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from datetime import datetime, timedelta

now = datetime.now()
start = now + timedelta(minutes = 15)
finish = start + timedelta(minutes = 30)

elapsed = finish - start
number_of_intervals = elapsed / timedelta(minutes=15)

elapsed is the timedelta between start and finish. Divide by 15 minutes to calculate how many 15 minute intervals fit in there.

Note that this returns a float, so includes fractional intervals. Round as appropriate.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading