Date strftime('%d%m%y') date to be of yesterday

Tim Golden mail at timgolden.me.uk
Thu Oct 22 12:36:50 CEST 2009


baboucarr sanneh wrote:
> 
> Hi tim,
> 
> well i tried what your script but i do have an error
>>>> import datetime
>>>> yesterday = datetime.date.today () - datetime.timedelta (days=1)
>>>> print yesterday.strftime ("%d%m%y")
> SyntaxError: invalid syntax (<pyshell#2>, line 1)
> 
> when i jus check the variable i.e yesterday i do get the out put but its in a different format
> datetime.date(2009, 10, 21)
> it seems like the conversion that is where the error is coming form 
> 
> I want it to be like 211009 
> 
> Thank you


I assume you're running Python 3.1? Try this:

print (yesterday.strftime ("%d%m%y"))

TJG



More information about the Python-list mailing list