by Sai gowtham

How to convert datetime.timedelta to string in Python

This following example shows you, how to convert a datetime.timedelta object to a human readable string format in Python.

import datetime

start = datetime.datetime(2020,8,10,13,00)
end   = datetime.datetime(2020,8,17,16,00)
delta = end-start
string_delta = str(delta)

print(delta)

Output:

7 days, 3:00:00

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
130,921 students enrolled
48.5 hours of video content
View Course