timedelta in years

0 votes
How to I convert timedelta duration into years?
Aug 8, 2019 in Python by Fata
• 1,050 points
14,453 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,960 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,522 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
20,016 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
1,308 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,885 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
6,407 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,510 points
122,344 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,960 points
570 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,960 points
6,299 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,960 points
763 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,960 points
2,714 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