Key Concepts

Review core concepts you need to learn to master this subject

Date and Time in Python

import datetime feb_16_2019 =, month=2, day=16) feb_16_2019 =, 2, 16) print(feb_16_2019) #2019-02-16 time_13_48min_5sec = datetime.time(hour=13, minute=48, second=5) time_13_48min_5sec = datetime.time(13, 48, 5) print(time_13_48min_5sec) #13:48:05 timestamp= datetime.datetime(year=2019, month=2, day=16, hour=13, minute=48, second=5) timestamp = datetime.datetime(2019, 2, 16, 13, 48, 5) print (timestamp) #2019-01-02 13:48:05

Python provides a module named datetime to deal with dates and times.

It allows you to set date ,time or both date and time using the date(),time()and datetime() functions respectively, after importing the datetime module .

Modules in Python
Lesson 1 of 1
  1. 1
    In the world of programming, we care a lot about making code reusable. In most cases, we write code so that it can be reusable for ourselves. But sometimes we share code that’s helpful across a br…
  2. 2
    datetime is just the beginning. There are hundreds of Python modules that you can use. Another one of the most commonly used is random which allows you to generate numbers or select items at random…
  3. 3
    Notice that when we want to invoke the randint() function we call random.randint(). This is default behavior where Python offers a namespace for the module. A namespace isolates the functions, cl…
  4. 4
    Let’s say you are writing software that handles monetary transactions. If you used Python’s built-in floating-point arithmetic to calculat…
  5. 5
    You may remember the concept of scope from when you were learning about functions in Python. If a variable is defined inside of a function, it will not be accessible outside of the function. …
  6. 6
    You’ve learned: - what modules are and how they can be useful - how to use a few of the most commonly used Python libraries - what namespaces are and how to avoid polluting your local namespace - …