Python Dates and Times in Python Dates and Times strftime & strptime

Tinayeshe Ngara
Tinayeshe Ngara
3,687 Points


Hi everyone, I'm finding it hard to pick up any errors from my code I have attached here. Can someone point in the right direction. Thanks!
## Examples
# to_string(datetime_object) => "24 September 2012"
# from_string("09/24/12 18:30", "%m/%d/%y %H:%M") => datetime
import datetime

def to_string(date1):
    return date1.strftime("%d %B %y")

1 Answer

Phil Livermore
Phil Livermore
11,016 Points

Use a capital Y for a four digit year. ("%d %B %Y")