You can download this code by clicking the button below.
This code is now available for download.
This function formats a datetime object into a string in the format of year-month-day.
Technology Stack : datetime
Code Type : Date formatting function
Code Difficulty : Beginner
import datetime
def date_to_string(date_obj):
return date_obj.strftime("%Y-%m-%d")