A problem with Time

syndrowm syndrowm at gmail.com
Thu Aug 16 11:48:46 EDT 2007


On 8/16/07, special_dragonfly <Dominic 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?
>
> Thank You
>
> Dominic
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list


The easiest way I have found, is to use epoch, subtract the length of time,
then convert back to whatever format.  24 hours  is 86400 seconds.

>>> import time
>>> time.localtime()
(2007, 8, 16, 9, 41, 28, 3, 228, 1)
>>> time.localtime(time.time() - 86400)
(2007, 8, 15, 9, 41, 21, 2, 227, 1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070816/7579b18e/attachment.html>


More information about the Python-list mailing list