Date Object Formatting Function

  • Share this:

Code introduction


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")                
              
Tags: