Velocity Reviews

Velocity Reviews (
-   Python (
-   -   Re: mktime, how to handle dates before 01-01-1970 ? (

Stef Mientki 10-06-2009 08:10 PM

Re: mktime, how to handle dates before 01-01-1970 ?
Stephen Hansen wrote:
> On Mon, Oct 5, 2009 at 4:54 PM, Stef Mientki <
> <>> 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

John Yeung 10-08-2009 09:36 PM

Re: mktime, how to handle dates before 01-01-1970 ?
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.


Tim Chase 10-09-2009 12:39 PM

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!


All times are GMT. The time now is 04:25 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.