A problem with Time

MRAB google at mrabarnett.plus.com
Thu Aug 16 15:46:21 EDT 2007


On Aug 16, 4:30 pm, "special_dragonfly" <Domi... at PLEASEASK.co.uk>
wrote:
> Hello,
>
> I need to return the date yesterday in the form DDMMYYYY. I looked through
> the modules: time, datetime and calendar but can't find anything that leaps
> out at me.
>
> The problem I'm having is that although I can use time.localtime and get a
> tuple of the year, month, day and so forth, I don't believe I can just minus
> 1 from the day, because I don't think it's cyclic, also, I can't see the
> date being linked in with the month.
>
> So is there any way of getting yesterdays date?
>
As well as the other replies, this also works (as far as I can tell!):

import time
today = time.localtime()
yesterday = today[ : 2] + (today[2] - 1, ) + today[3 : ]
yesterday = time.localtime(time.mktime(yesterday))




More information about the Python-list mailing list