Re: mktime, how to handle dates before 01-01-1970 ?

Discussion in 'Python' started by Stef Mientki, Oct 6, 2009.

  1. Stef Mientki

    Stef Mientki Guest

    Stephen Hansen wrote:
    > On Mon, Oct 5, 2009 at 4:54 PM, Stef Mientki <
    > <mailto:>> wrote:
    > hello,
    > I want to handle datetime vars in a general way, so I use the
    > default time-format,
    > so I can use the standard cinversion procedures.
    > Personally, I love mx.DateTime; its the best date/time library around.
    > But, Python's built in datetime isn't too bad and is similar and
    > built-in if you don't want to use a third-party library.

    thanks guys,
    mx works a bit better ....
    > But:
    > >>> birthday = mx.DateTime.Date(1960,3,3)
    > >>> birthday

    > <mx.DateTime.DateTime object for '1960-03-03 00:00:00.00' at 6211e0>
    > >>> age = - birthday
    > >>> print "Age in days", age.days

    > 18113.722499758693
    > >>> print "Age in years", age.days / 365

    > 49.626636985640253
    > I really can't quite fathom why you'd want to use something so
    > low-level as time.mktime... or just about anything in the time module :)

    I didn't know anything better,
    but (forgive me if I'm wrong) I find mx almost as low-level :
    >>> mx.DateTime.strptime('01-01-53',"%d-%m-%y")

    <mx.DateTime.DateTime object for '2053-01-01 00:00:00.00' at 1cddc60>
    while all we human know ..

    I agree it's better not to work with string dates, but that's the way
    how we human write things down ;-)
    So I must use at least something like strptime.


    > If you want to handle dates in a general way, I'd use one of the
    > general-purpose date/time handling libraries. They're far more capable
    > and easier to use.
    > HTH,
    > --S
    Stef Mientki, Oct 6, 2009
    1. Advertisements

  2. John Yeung

    John Yeung Guest

    On Oct 6, 4:10 pm, Stef Mientki <> wrote:
    > thanks guys,
    > mx works a bit better  ....

    Another popular Python date library is dateutil:

    It gives a certain amount of credit to mxDateTime (praising it but not
    being very clear how they are related; there is some mention of "using
    the specification" of mxDateTime).

    I would say mxDateTime and dateutil are the two heavyweights in this
    arena. As you would expect, they have a lot of overlapping
    functionality and which one is used is often just a matter of taste,
    or whichever one you happened to find first.

    One thing that dateutil provides that mxDateTime doesn't is support
    for "lay person" month operations. That is, as far as I can tell,
    mxDateTime tries not to dirty itself with the messy business of month
    arithmetic, whereas dateutil rolls up its sleeves and takes an honest
    stab at it. If you are writing a calendar/appointment application, or
    other end-user-facing program, I would expect dateutil to be a little
    more helpful.

    John Yeung, Oct 8, 2009
    1. Advertisements

  3. Tim Chase

    Tim Chase Guest

    Re: mxDateTime history (Re: mktime,how to handle dates before 01-01-1970 ?)

    > Month arithmetic is a bit of a mess, since it's not clear how
    > to map e.g. Jan 31 + one month.

    "Jan 31 + one month" usually means "add one to the month value
    and then keep backing off the day if you get an exception making
    the date", so you'd get Feb 31, exception, Feb 30, exception, Feb
    29, possibly an exception, and possibly/finally Feb 28th. This
    makes pretty intuitive sense to most folks and is usually what's

    I've found that issues and confusion stem more from the
    non-commutative reality that "Jan 31 + (1 month) + (-1 month) !=
    Jan 31 + (-1 month) + (1 month)" or the non-associative "Jan 31 +
    (1 month + 1 month) != (Jan 31 + 1 month) + 1 month" :-/

    So yes, messy it is!

    Tim Chase, Oct 9, 2009
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Rob Schieber
    Sep 30, 2005
  2. Stef Mientki
    John Yeung
    Oct 8, 2009
  3. Stef Mientki
    Stef Mientki
    Oct 8, 2009
  4. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Mark Schupp
    Aug 9, 2004
  5. Kevin Howe

    dates earlier than 1970?

    Kevin Howe, Nov 3, 2004, in forum: Ruby
    Yukihiro Matsumoto
    Nov 3, 2004

Share This Page