---
title: Printing dates in Python with the datetime module
description: Printing dates in Python with the datetime module
---

[Skip to content](https://www.connysoderholm.com/blog/python-datetime-module#main-content)

![Conny-Söderholm](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg)

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

Open main navigation

Close main navigation

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

 June 20, 2018

# Printing dates in Python with the datetime module

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm)

Share: [facebook-f icon](http://www.facebook.com/share.php?u=https://www.connysoderholm.com/blog/python-datetime-module) [linkedin-in icon](http://www.linkedin.com/shareArticle?mini=true&url=https://www.connysoderholm.com/blog/python-datetime-module) [Twitter icon](https://twitter.com/intent/tweet?url=https://www.connysoderholm.com/blog/python-datetime-module) [pinterest-p icon](http://pinterest.com/pin/create/link/?url=https://www.connysoderholm.com/blog/python-datetime-module) [envelope icon](mailto:?body=https://www.connysoderholm.com/blog/python-datetime-module)

*Printing dates in Python with the datetime module* - Today we are going to dive into the [datetime](https://docs.python.org/3.6/library/datetime.html) module. The datetime module is useful if you want to know the current time or make time calculations. In the below example we are creating some different time examples. I also created a thread so that we can end the execution with any keypress.

```
#! python3

import datetime
import time
import threading

def input_thread(my_input_list):
input()
my_input_list.append("I detect key presses")

def my_date_time_ticker():
my_input_list = []
threading.Thread(target=input_thread, args = (my_input_list,)).start()

while True:
if my_input_list: break
time_now = str(datetime.datetime.now())
year = datetime.date.today().strftime("%Y")
month = datetime.date.today().strftime("%B")
week_nr = datetime.date.today().strftime("%W")
weekday = datetime.date.today().strftime("%A")
week_day_nr = datetime.date.today().strftime("%w")
day_nr_of_year = datetime.date.today().strftime("%j")
day_nr_of_month = datetime.date.today().strftime("%d")
print("Press any key to exit")
print("Todays date is:", datetime.date.today())
print("The exact time now is" , time_now)
print("The current year is" , year)
print("The current month is" , month)
print("Day number of year:", day_nr_of_year)
print("Day number of month:", day_nr_of_month)
print("The current week number is:" , week_nr)
print ("Today is" , weekday, "which has the weekday number of:" , week_day_nr)
print()
time.sleep(1)

if __name__ == "__main__":
my_date_time_ticker()
print("Program terminated")
```

 

Happy coding!

[Python](https://www.connysoderholm.com/blog/tag/python)

## Related posts

[Python](https://www.connysoderholm.com/blog/tag/python)

## [How to run a multi-thread in Python](https://www.connysoderholm.com/blog/multithread-python)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 July 14, 2018

Introduction How to run a multi-thread in Python - While coding, we sometimes want the program to...

[Read more](https://www.connysoderholm.com/blog/multithread-python)

[Python](https://www.connysoderholm.com/blog/tag/python), [openpyxl](https://www.connysoderholm.com/blog/tag/openpyxl), [Excel](https://www.connysoderholm.com/blog/tag/excel)

## [Copy Excel data to workbook with Python & OpenPyXL](https://www.connysoderholm.com/blog/copy-data-from-one-excel-workbook-to-a-new-workbook-with-python-openpyxl)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 December 16, 2019

[Read more](https://www.connysoderholm.com/blog/copy-data-from-one-excel-workbook-to-a-new-workbook-with-python-openpyxl)

[Python](https://www.connysoderholm.com/blog/tag/python)

## [Creating a simple file dialog box with Tkinter](https://www.connysoderholm.com/blog/file-dialog-box-tkinter)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 June 14, 2018

Creating a simple file dialog box with Tkinter - Have you come to a point when you want to avoid...

[Read more](https://www.connysoderholm.com/blog/file-dialog-box-tkinter)

[linkedin-in icon](https://www.linkedin.com/in/connysoderholm) [Follow us on Facebook](https://www.youtube.com/@connysoderholm1473)

- [Home](https://www.connysoderholm.com)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)
- [Privacy Policy](https://www.connysoderholm.com/privacy-policy)
- [Disclaimer](https://www.connysoderholm.com/disclaimer)

---

[![Conny Söderholm Logo](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg "Conny Söderholm Logo")](http://Conny%20Söderholm)

Copyright © 2026 Conny Söderholm

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Conny Söderholm",
    "url" : "https://www.connysoderholm.com/blog/author/conny-soderholm"
  },
  "dateModified" : "2023-07-31T15:09:55.940Z",
  "datePublished" : "2018-06-20T16:44:56.000Z",
  "headline" : "Printing dates in Python with the datetime module",
  "mainEntityOfPage" : {
    "@id" : "https://www.connysoderholm.com/blog/python-datetime-module",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg"
    },
    "name" : "Conny Söderholm"
  }
}
```