How to convert Python datetime object to a String

One of the most common operations one needs to do is converting datatime object to a str string object in Python.

To achieve this you need to make use of the strftime() method from datatime module.

import datetime

dt =
date_format = '%d-%m-%Y'
formatted_date = dt.strftime(date_format)


We have got the current date and time suing and converted it into date in dd-MM-yyyy date format.

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap