yesterday's date

Harald Kirsch kirschh at lionbioscience.com
Thu May 10 02:57:11 EDT 2001


"Matt Setzer" <dontspamsetzer at nwlink.com> writes:

>     Subtract one day (in seconds) from the value returned by time.time(),
> then convert it to a string.
> 
> >>> import time
> >>> ticks = time.time()
> >>> time.asctime(time.localtime(ticks - 24 * 60 * 60))
> 'Tue May 08 19:08:08 2001'
> >>>

Be careful on the single day in a year that has 25 hours of localtime
due to Daylight Saving Time.

You rather should simply substract 1 from the day, even if it
underflows to 0, and pass that to mktime, like

>>> localtime(mktime((2000,1,0,0,0,0,0,0,0)))
(1999, 12, 31, 0, 0, 0, 4, 365, 0)

The zeroth January 2000 is correctly converted into Dec. 31 1999.

  Harald Kirsch
-- 
----------------+------------------------------------------------------
Harald Kirsch   | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172          |        -- Paul Erdös
       *** Please do not send me copies of your posts. ***



More information about the Python-list mailing list