[Tutor] is mxDateTime recommended?
Lance E Sloan
lsloan at umich.edu
Sat Oct 22 02:13:23 CEST 2005
--On Thursday, October 20, 2005 4:44 PM -0400 Kent Johnson <kent37 at tds.net>
> Since 2.3 Python includes a datetime module which has some facility for
> date calculations. I think mxDateTime is more sophisticated but if your
> needs are simple take a look at datetime.
I think I would like to use the "datetime" module included with Python,
just so I don't need to worry about an additional piece of code, the
In my code, I set up some mxDateTime RelativeDateTime objects that will be
secondLockBeginsDelta = DateTime.RelativeDateTime( day = 14, hour = 23,
minute = 59, months = -4 )
When I add that to another mxDateTime object, the month, hour, and minute
get set to those absolute values, but the month is reduced by four. I know
I won't be able to exactly the same thing with datetime. I think I could
do something like this (semi-pseudocode):
firstTime = datetime.now()
secondTime = firstTime - timedeltaFourMonthsObject
secondTime.replace( day = 14, hour = 23, minute = 59 )
The problem is that I can't figure out how to create that
timedeltaFourMonthsObject. The datetime timedelta class constructor
doesn't allow creating a delta with a month. Any suggestions?
(I think it's a little too bad that the timedelta class represents all
deltas as days and seconds. That must be why they don't support months,
since months have different lengths. IMHO...)
Also, how can I make a copy of a datetime object?
timeA = datetime.now()
timeB = timeA # copy or reference to same object?
Lance E Sloan, Systems Research Programmer III
U-M WATS: Web Applications, Technologies, and Solutions
Full-service web and database design, development, and hosting.
http://www.itcs.umich.edu/wats/ - "Putting U on the Web"
More information about the Tutor