timedelta in years

0 votes
How to I convert timedelta duration into years?
Aug 8, 2019 in Python by Fata
• 1,050 points
13,744 views

1 answer to this question.

0 votes

Use the following piece of code:

x1=datetime.timedelta(days=3000, seconds=0, microseconds=0, milliseconds=0, minutes=40, hours=5, weeks=8)
x2=datetime.timedelta(days=345, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=4, weeks=8)
x3=x1-x2
x4=x3.days/(366)
print("Years: ",x4)

OUTPUT:

2655 days, 1:40:00
Years:  7.254098360655738
answered Aug 8, 2019 by Wajiha
• 1,950 points

Related Questions In Python

0 votes
1 answer

Can someone help me understand timedelta in Python?

Because timedelta is defined like: class datetime.timedelta([days,] [seconds,] ...READ MORE

answered Jan 16, 2019 in Python by charlie_brown
• 7,720 points
1,293 views
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,890 points
19,299 views
+2 votes
2 answers

How can I create a new file in Python?

You can try the below code which ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
950 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
4,229 views
+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
5,193 views
+2 votes
4 answers

How can I replace values with 'none' in a dataframe using pandas

Actually in later versions of pandas this ...READ MORE

answered Aug 13, 2018 in Python by bug_seeker
• 15,520 points
118,946 views
0 votes
1 answer

converting string into datetime

You can make use of asctime() method ...READ MORE

answered Aug 7, 2019 in Python by Wajiha
• 1,950 points
385 views
0 votes
1 answer

converting timedelta to float

Use the following piece of code: x1=datetime.timedelta(days=3000, seconds=0, ...READ MORE

answered Aug 8, 2019 in Python by Wajiha
• 1,950 points
5,525 views
0 votes
1 answer

What is timedelta in python?

It represents a duration which is basically ...READ MORE

answered Aug 7, 2019 in Python by Wajiha
• 1,950 points
545 views
0 votes
1 answer

Performing divison on timedelta object in python?

Refer the following piece of code: e1=datetime.timedelta(days=32, seconds=0, ...READ MORE

answered Aug 13, 2019 in Python by Wajiha
• 1,950 points
2,359 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP