Wednesday, August 27, 2008

Python: Datetime Math

#start code
import datetime
from datetime import datetime as dt
oneDay = datetime.timedelta(days=1)
tomorrow = dt.today()+oneDay
kmlTimeFormat = tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ")
#end code

timedelta resides in the datetime module
today() resides in the datetime.datetime module

then add timedelta (can use months, hours, days, ...) to your datetime.datetime object

I added the kml date string format because thats what i am working on at the moment.


more info

2 comments:

Unknown said...

Completly useless info. Nothing anyone cant find on the python web site. Why dont you offer something more substantial like explaining the details behind adding and subtraction datetime objects and using the results in a real-world application.
Now that would actually be helpful

Unknown said...

To the previous commentator, "Unknown" the only useless thing I found on this page is your comment. Your rude, arrogant, and useless. You should break your keyboard and never buy another one.