[egenix-users] mxDateTime problem

Charlie Clark charlie at egenix.com
Mon May 5 11:51:10 CEST 2008


Am 05.05.2008, 10:37 Uhr, schrieb Dick Moores <rdmoores at gmail.com>:

Dick,

it would be nice to have the problem stated clearly at the top of the  
e-mail.

> Use this file for temporary saving. E.g. for drafting an email.
> Please see my daysDelta24.py at  
> <http://py77.python.pastebin.com/f5d8a35d>
> "Compute the difference in days (and weeks and days) between 2 dates.
> E.g., The difference between 07/04/1776 and 09/11/2001 is 82248 days
> Or 11749 weeks and 5 days"
> The user is instructed to "Enter date as month/day/year, or enter
> nothing for today", for both dates. If for one date he chooses to
> enter nothing in order to make that date today's date, the script
> fails--the computed difference between the dates will be short by 1.
> Thus, if the dates are 5/5/2008 (today's date entered by entering
> nothing) and 5/8/2008, the computed difference will be 2. If instead,
> both of these dates had been entered "manually", the computed
> difference will be 3. (See outputs #3 and #4, lines 107-126)
> I believe the error is caused by getDate() returning DT.now() when the
> user enters "".  DT.now() is, for example, 2008-05-05 00:51:34.00 (my
> local time at time of writing), not 2008-05-05 00:00:00.00, whereas
> the other date entered, for example 5/8/2008, will be returned as
> 2008-05-11 00:00:00.00.
>
>>>> from mx import DateTime as DT
>>>> print DT.now()
> 2008-05-05 00:51:34.00
>>>> dstr = "5/8/2008"
>>>> print DT.Parser.DateFromString(dstr, ('us',))
> 2008-05-08 00:00:00.00
>>>>

This is the problem?

> In line 48 (2008-08-11 00:00:00.00 - 2008-05-05 00:51:34.00).days will
> be computed as 2 days, not 3.

Well, the difference between the two datetimes is 2 days + 23 hours... and  
you are only asking for the days.

> I've used mxDateTime instead of the Python module datetime because
> datetime can't handle dates earlier than the year 1900.
> Can anyone tell me how to correct this problem?

You should coerce mx.DateTime.now() to create a Date object (ie. no time).  
That should solve your problem.

Charlie
-- 
Charlie Clark
eGenix.com

Professional Python Services directly from the Source
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::

     eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
            Registered at Amtsgericht Duesseldorf: HRB 46611



More information about the egenix-users mailing list