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

python how to get the day in the median between two days

I have two timestamps:

t1 = Timestamp('2020-01-01 00:00:00')
t2 = Timestamp('2020-01-07 06:00:00')]

I want to get the timestamp that is exactly in the middle between them, with one hour resolution:

tm = Timestamp('2020-01-04 03:00:00')]

if the number of timestamps is not odd (2 values in the middle), just pick one of the two.

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

>Solution :

This is actually quite easy with timestamps:

The difference between the two timestamps can be computed by t2 - t1. Half of this can be computed by (t2 - t1) / 2. Now round this by using .floor('H'). This needs to be added by t1 and you got your result!

tm = t1 + ((t2 - t1) / 2).floor('H')
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