[egenix-users] mxDateTime problem

M.-A. Lemburg mal at egenix.com
Mon May 5 11:53:03 CEST 2008


On 2008-05-05 10:37, Dick Moores wrote:
> 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 "". 

If you change your getDate() to use DateTime.today() the
problem should go away.

The mxDateTime parsers default to 00:00:00 for the time
part if no time part is found. DateTime.today() does the
same - it returns the current date at midnight.

> 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
> 
> 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.
> 
> 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?
> 
> Thanks,
> 
> Dick Moores

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 05 2008)
 >>> 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