Finding mid-point date between two dates in Python

前端 未结 2 798
花落未央
花落未央 2020-12-11 00:49

Given dates:

my_guess = \'2014-11-30\'
their_guess = \'2017-08-30\'

How do I split the delta between the dates, returning the correct calen

2条回答
  •  长情又很酷
    2020-12-11 01:34

    from datetime import datetime
    d1 = datetime.strptime(my_guess,"%Y-%m-%d")
    d2 = datetime.strptime(their_guess,"%Y-%m-%d")
    print d1.date() + (d2-d1) / 2 # first date plus the midpoint of the difference between d1 and d2  
    2016-04-15 
    

提交回复
热议问题