Can anyone suggest a date peocedure...

Gary Herron gherron at islandtraining.com
Thu Jul 10 16:39:29 EDT 2008


RLV wrote:
> I'd like to find a simple... (I'm a simple person) procedure to
> subtract a numerical number from a six char date string 
> YYYYMMDD and then convert back to a new date string.
>
> I'm sure there's a way to do it, but the date modules haven't been
> much help.
>
> TIA
> Ron
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>   

The datetime module has what you need.

It has methods (with examples) on building a datetime object from a 
string, and it has a object named timedelta, and the ability to subtract 
a timedelta from a time.

For instance, the time right now and the time exactly one day ago:

 >>> from datetime import *
 >>> datetime.today()
datetime.datetime(2008, 7, 10, 13, 38, 48, 279539)
 >>> datetime.today()-timedelta(1)
datetime.datetime(2008, 7, 9, 13, 38, 50, 939580)


Gary Herron




More information about the Python-list mailing list