tomorrow in yyyymmdd format

Bjorn Pettersen BPettersen at NAREX.com
Tue Jun 18 20:36:28 EDT 2002


> From: Gerhard Häring [mailto:gerhard at bigfoot.de] 
> 
> Giulio Cespuglio wrote in comp.lang.python:
> > Hello everybody,
> > 
> > We all know that if I want to get the present GMT date in yyyymmdd 
> > format I should say
> > 
> > 	print time.strftime("%Y%m%d", time.gmtime() )
> > 
> > Now, what about tomorrow? Note that a simple string manipulation is 
> > not the solution I'm looking for, as tomorrow might be next month, 
> > next year, the 29th of February and such. Do you confirm 
> that there's 
> > nothing better than the following silly-looking expression?
> > 
> > 	time.strftime("%Y%m%d", time.gmtime(time.time() + 60*60*24))
> 
> No, there's nothing better. Unless you're using the DateTime 
> type from the eGenix mxExtensions:

Sure there is :-) time.mktime() can take a "malformed" time tuple and do something sensible with it. You can therefore get a time tuple from gmtime, add one to the day position and call time.mktime() on the result:

>>> x = (2002, 2, 29, 0, 31, 42, 2, 170, 0)
>>> time.gmtime(time.mktime(x))
(2002, 3, 1, 7, 31, 42, 4, 60, 0)
>>>

-- bjorn





More information about the Python-list mailing list