Skip to content
Learnearn.uk » Python Unit Home » Python Date and Time Tutorials

Python Date and Time Tutorials

Time module

import time

time.time()

time.sleep(5)

duration between two times

start = time.time()

input(“press enter”)

end = time.time()

duration = end – start

Datetime module

Get the current date

Get the current time

Get the current date and time

Find out specific bits of the date

Convert the date to a pretty string

Convert a string formatted date in to a datetime object

Cheat Sheet

Here is a handy reference sheet to download and print.

Countdown tracker

Bronze

  • Create an app that asks the user to enter a date and an event name.
  • The app should then display the number of days left until that date

Silver

  • The app should persistently store the date and event name, displaying it each time the user loads the app in future

Gold

  • Expand your app to be a complete event tracker, allowing multiple events
  • The ability to add / remove events

Calendar viewer app

Bronze

  • Create an app that asks the user to input a year and month.
  • It should then print out that month’s calendar to the user.

Silver

  • The app should check that the user has entered a valid year and month, and force the user to reenter the value until a valid amount has been entered.

Gold