Zope+FB+mx - DateTime errrrrrrrror....
Chris Irish
chris.irish at libertydistribution.com
Thu Aug 19 14:32:41 EDT 2004
fowlertrainer at anonym.hu wrote:
> Hi !
>
> I think that I have been found a bug in mx.DateTime...
> So:
> I use FireBird, and in this RDBMS the datetime fields are "doubles".
> So if I set them to 0, the values the fields are '1899-12-30 01:00:00'.
>
> When I try to see this datetime as European format (YYYY.MM.DD HH:MM:SS)
> I get error.
>
> Example1:
> s='1899-12-30 01:00:00'
> nv=str(s)
> nv=DateTime(s)
> s=nv.strftime('%Y.%m.%d. %H:%M:%S')
> # it is makes error
>
Well I'm no expert on the mx.Datetime module, but lets so if I can
help. In your example #1 I tried doing it in the interpretor exactly as
you did and ran into some problems. First, you set 's' equal to a
string of the date your wanting I presume. Then your calling the
builtin str method on it. Why when it's already a string? Then your
calling the DateTime method however it needs to be qualified through the
mx.DateTime module
i.e.
import mx.DateTime
mx.DateTime.DateTime(s)
However your passing in s to this method as a string. In the
mx.DateTime docs it says and I quote,
"|DateTime(year,month=1,day=1,hour=0,minute=0,second=0.0)|
Constructs a DateTime instance from the given values.
So you need to be passing in integer values except for the seconds
argument which can be a float. If you call the method in the correct
way it will return a datetime object of the date you want then you can
use strftime to format it in the european fasion yu desire. One final
note all datetime objects are created with a 24 hour time, not 12. So
5pm will be 17:00 after you string format the object, if my memory is
correct. Just remember that for if/when you take those times back out
of the database to display to a user you'll need to change them to a 12
hour time, unless they don't mind reading it like that. We use
PostgreSQL for our databases and whenever a time object is put into the
database it is automatically converted to ticks. I'm not sure if it's
the same way with yours or not. So when pulling a time back out it
would be converted like:
time = mx.DateTime.localtime(item_object_fromDB).strftime("%m/%d/%Y
etc....")
There is also another method called strptime which parses a time string
according to a particular format but I haven't used it enough to
instruct you on it's us, but it could be helpful.
Hopefully something I said will help, be sure to look at the docs @:
http://www.egenix.com/files/python/mxDateTime.html#DateTime
and
http://docs.python.org/lib/module-time.html
Good Luck, Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040819/0e848ef0/attachment.html>
More information about the Python-list
mailing list