How to Import timedelta in Python (2 Examples)


In this Python tutorial, you’ll learn how to import timedelta from the datetime module.

The tutorial looks as follows:

It’s time to dive into the examples!


Example 1: Importing timedelta

In Example 1, I’ll demonstrate the easiest way to import timedelta.

from datetime import timedelta    # Importing timedelta

The “from” keyword is used to specify the parent module and the “import” parameter is used to specify the part of the module that should be imported. In this case, we want to import timedelta from the datetime module.


Example 2: Importing timedelta with an Alias

Example 2 explains how to import timedelta with an alias.

from datetime import timedelta as td

In this case, the “as” keyword is employed to set an alias to be used in the Python script. From then on, timedelta is called “td”.


Video, Further Resources & Summary

Do you need further information on the Python programming code of this tutorial? Then I recommend watching the following video on my YouTube channel. I’m explaining the Python programming codes of this article in the video:


The YouTube video will be added soon.


Furthermore, you may want to have a look at the other articles on my homepage:


To summarize: In this tutorial, I have illustrated how to load timedelta module in Python programming. Don’t hesitate to tell me about it in the comments, in case you have any additional questions.


Ömer Ekiz Python Programming & Informatics

This page was created in collaboration with Ömer Ekiz. Have a look at Ömer’s author page to get further information about his professional background, a list of all his tutorials, as well as an overview on his other tasks on Statistics Globe.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.