Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Convert time difference to float value using python? [Closed]

By
Jo
on 12/4/14, 4:39 AM 4,899 views

The Question has been closed for reason: duplicate question

by
Atchuthan - Technical Consultant, Sodexis Inc
on 12/04/2014 10:47:07

Hi all,

my time format is '%Y-%m-%d %H:%M:%S'

start_time = 2014-12-04 08:10:32

end_time = 2014-12-04 12:34:45

Here i want output like diff_time = 4.24

Thanks in advance...

https://www.odoo.com/forum/help-1/question/how-to-find-out-number-of-hours-between-two-datetime-object-69367#answer-69386

Atchuthan - Technical Consultant, Sodexis Inc
on 12/4/14, 10:47 AM
2
shashank verma
On 12/4/14, 7:39 AM

Hello Jothimani,

Code:

from datetime import datetime
fmt = '%Y-%m-%d %H:%M:%S'
d1 = datetime.strptime('2014-12-04 08:10:32',fmt) #start date
d2=datetime.strptime('2014-12-04 12:34:45',fmt)   #end date

diff=d2-d1  #calculate difference between start-end date
total seconds=diff.seconds

final output=total seconds/3600.0   #convert total seconds into hours Difference in float format

 

0
Demirel yakito
On 12/29/14, 4:38 AM

import time

start_h=time.strftime('%I')
start_m=time.strftime('%M')
start_s=time.strftime('%S')

end_h=time.strftime('%I')
end_m=time.strftime('%M')
end_s=time.strftime('%S')

print int(start_h)-int(end_h), int(start_m)-int(end_m), int(start_s)-int(end_s)

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 12/4/14, 4:39 AM
Seen: 4899 times
Last updated: 3/16/15, 8:10 AM