Skip to content

Instantly share code, notes, and snippets.

@tamalchowdhury
Last active December 30, 2020 12:26
Show Gist options
  • Select an option

  • Save tamalchowdhury/96dc2f9c126c32f5ff03b972ee64da08 to your computer and use it in GitHub Desktop.

Select an option

Save tamalchowdhury/96dc2f9c126c32f5ff03b972ee64da08 to your computer and use it in GitHub Desktop.
Convert date to dd-mm-yyyy with Python
# This function takes a date and converts into
# desired format dd-mm-yyyy
# Use inside a loop to make the conversion
def convert_date(dateobject):
return dateobject.strftime('%d-%m-%Y')
# Example
from datetime import datetime
date_stamp = datetime.today()
print(convert_date(date_stamp))
# >>> 30-12-2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment