How to compute the difference of two datetime fields and have the results in float?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
The differnce of two datetime filedswoul be in a datetime format.eg: 0:45:00 . IF you need to type cast to float then you will get ValueError: invalid literal for float(): 0:45:00. So solution is either you can split it and cast to float or take result as seconds and convert to float.
eg:Input : datetime(0:45:00)
print float((end_date-date).seconds)
2700.0
print [float(i) for i in str((end_date-date)).split(":")]
[0.0, 45.0, 0.0]
The following should work. You would most likely have the following code execute on change of either datetime field. note: time_diff is a float field.
time_diff = fields.Datetime.from_string(self.later_datetime) - fields.Datetime.from_string(self.earlier_datetime)
self.time_diff= float(time_diff.days) * 24 + (float(time_diff.seconds) / 3600)
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
3
jul. 23
|
27383 | ||
|
2
jun. 22
|
5829 | ||
|
2
sep. 21
|
4852 | ||
|
1
nov. 20
|
8131 | ||
|
2
mrt. 19
|
6241 |