timedelta in years

0 votes
How to I convert timedelta duration into years?
Aug 8 in Python by Fata
• 1,000 points
30 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 by Wajiha
• 1,840 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 in Python by charlie_brown
• 7,720 points
25 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,810 points
115 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,420 points
81 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,420 points
1,218 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
80 views
+2 votes
2 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,350 points
4,913 views
0 votes
1 answer

converting string into datetime

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

answered Aug 7 in Python by Wajiha
• 1,840 points
15 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 in Python by Wajiha
• 1,840 points
23 views
0 votes
1 answer

What is timedelta in python?

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

answered Aug 7 in Python by Wajiha
• 1,840 points
19 views
0 votes
1 answer

Slicing a list using a variable, in Python

Yes its possible. Use the following piece ...READ MORE

answered Jul 2 in Python by Wajiha
• 1,840 points
18 views