how to manipulate date operation??

Calvelo Daniel dcalvelo at pharion.univ-lille2.fr
Mon Sep 4 06:50:57 EDT 2000


ykchew <ykchew at hotmail.com> wrote:
: hi there,
:     i'm new to python, i wish to know how to manipulate the date like
:     Today + 1 day and
:     Today + 1 hour

Fetch the mxDateTime module.

>>> import DateTime
>>> DateTime.now() 
<DateTime object for '2000-09-04 13:58:07.02' at 809beb8>
>>> DateTime.now() + 2*DateTime.oneHour 
<DateTime object for '2000-09-04 15:58:22.50' at 809beb8>

or use the standard time module:

>>> import time 
>>> time.ctime(time.time())
'Mon Sep  4 14:00:36 2000'
>>> time.ctime( time.time() + 2*60*60 )
'Mon Sep  4 16:00:55 2000'

I'd use the former if you start fiddling with dates. Hours, minutes and 
seconds are simple enough for the latter.

HTH, DCA

-- Daniel Calvelo Aros
     calvelo at lifl.fr



More information about the Python-list mailing list