Thomas Guettler <[EMAIL PROTECTED]> writes:

> Am Wed, 05 Jan 2005 15:08:37 +0100 schrieb Nader Emami:
>
>> L.S.,
>> 
>> Could somebody help me how I can get the next format of date
>> from the time module?
>
> I don't understand your question. Do you want to have the next day?
>
> 20041231 --> 20050101 ?
>
> You can do it like this:
>  - parse the string with time.strptime
>  - timetuple[2]+=1
>  - mktime(timetuple) # --> secs
>  - strftime(localtime(secs))
Or using the datetime module:

import time, datetime

tt = time.strptime('20041231', '%Y%m%d')
t = datetime.date.fromtimestamp(time.mktime(tt))
# now in a easier-to-handle form than the time tuple
t += datetime.timedelta(days=1)
print t.strftime('%Y%m%d')


-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to