i have 3 fields
check_in_date = fields.Char(string="DateTime Opened", required=False, )
mttr_time = fields.Float(string="MTTR", required=False, )
check_out_date = fields.Datetime(string="DateTime Closed", required=False, )
am trying to get the time difference between 2 datetimes having different formats and here is my function
@api.onchange('check_in_date', 'check_out_date', 'mttr_time')
def calculate_timer(self):
if self.check_in_date and self.check_out_date:
t1 = datetime.strptime(self.check_in_date, '%m/%d/%Y %H:%M:%S')
print('=================================T1')
print('=================================')
print(t1)
print('=================================')
print('=================================')
t2 = datetime.strptime(self.check_out_date, '%Y-%m-%d %H:%M:%S')
print('=================================T2')
print('=================================')
print(t2)
print('=================================')
print('=================================')
t3 = t2 - t1
print('=================================T3')
print('=================================')
print(t3)
print('=================================')
print('=================================')
self.mttr_time = float(t3.days) * 24 + (float(t3.seconds) / 3600)
however if i set the two datetimes to be same/equal i get a difference of negative three(-3.00) hours as shown on this link https://imgur.com/TjnKWY4 am trying to figure out the issue but its like i cant find any assistance will be appreciated
You just need to play with dates:
1- http://learnopenerp.blogspot.com/2018/01/python-date-manipulation.html
2- http://learnopenerp.blogspot.com/2018/02/python-strftime-datetime-formatting.html
3- http://learnopenerp.blogspot.com/2018/02/python-timedelta.html