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

Stef Mientki stef.mientki at gmail.com
Tue Oct 6 22:10:57 CEST 2009


Stephen Hansen wrote:
> On Mon, Oct 5, 2009 at 4:54 PM, Stef Mientki <stef.mientki at gmail.com 
> <mailto:stef.mientki at gmail.com>> 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 = mx.DateTime.now() - 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.

cheers,
Stef

> 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
>
>




More information about the Python-list mailing list