datetime - no attribute 'isoformat'?

4,938 views
Skip to first unread message

Bleve

unread,
May 28, 2010, 8:50:05 AM5/28/10
to wxPython-users
G'day,
I'm a newbie to wxPython, this is probably something really dumb on my
part but I'm stuck and have been googling to no avail for some time
now.

My code :

import time
import datetime
import wx
.
.
.
self.date = wx.DatePickerCtrl(self, -1)

.
.
.

my_date = self.date.GetValue()
isodate = my_date.isoformat()


The error :
AttributeError: 'DateTime' object has no attribute 'isoformat' - I'm
trying to insert this into a MySQL database using MySQLdb so the ISO
format is kinda important!

Is the wx.DateTime not the same as a normal python datetime? Can
anyone tell me what I've got wrong?
Python 2.6 on Win32 (XP) and wxPython 2.8.10.1

Thank you,

Carl



Cody Precord

unread,
May 28, 2010, 12:16:49 PM5/28/10
to wxpytho...@googlegroups.com
Hi,

On Fri, May 28, 2010 at 7:50 AM, Bleve <carl.i...@gmail.com> wrote:
>
>        my_date = self.date.GetValue()
>        isodate = my_date.isoformat()
>
>
> The error :
> AttributeError: 'DateTime' object has no attribute 'isoformat' - I'm
> trying to insert this into a MySQL database using MySQLdb so the ISO
> format is kinda important!
>
> Is the wx.DateTime not the same as a normal python datetime?  Can
> anyone tell me what I've got wrong?

No, they are not the same they are two completely different classes.
Though they have the same purpose.

See wx.DateTime.Format
http://docs.wxwidgets.org/2.8/wx_wxdatetime.html


Cody

GadgetSteve

unread,
May 29, 2010, 4:26:45 AM5/29/10
to wxpytho...@googlegroups.com

--------------------------------------------------
From: "Bleve" <carl.i...@gmail.com>
Sent: Friday, May 28, 2010 1:50 PM
To: "wxPython-users" <wxpytho...@googlegroups.com>
Subject: [wxPython-users] datetime - no attribute 'isoformat'?

> G'day,
> I'm a newbie to wxPython, this is probably something really dumb on my
> part but I'm stuck and have been googling to no avail for some time
> now.
>
> My code :
>
> import time
> import datetime
> import wx
> .
> .
> .
> self.date = wx.DatePickerCtrl(self, -1)
>
> .
> .
> .
>
> my_date = self.date.GetValue()
> isodate = my_date.isoformat()
>

Try:
isodate = mydate.FormatISODate()

>
> The error :
> AttributeError: 'DateTime' object has no attribute 'isoformat' - I'm
> trying to insert this into a MySQL database using MySQLdb so the ISO
> format is kinda important!
>
> Is the wx.DateTime not the same as a normal python datetime? Can
> anyone tell me what I've got wrong?
> Python 2.6 on Win32 (XP) and wxPython 2.8.10.1
>
> Thank you,
>
> Carl
>
>
>

> --
> To unsubscribe, send email to wxPython-user...@googlegroups.com
> or visit http://groups.google.com/group/wxPython-users?hl=en
>

Bleve

unread,
May 29, 2010, 5:52:17 AM5/29/10
to wxPython-users


On May 29, 2:16 am, Cody Precord <codyprec...@gmail.com> wrote:
> Hi,
>

> > Is the wx.DateTime not the same as a normal python datetime?  Can
> > anyone tell me what I've got wrong?
>
> No, they are not the same they are two completely different classes.
> Though they have the same purpose.
>
> See wx.DateTime.Formathttp://docs.wxwidgets.org/2.8/wx_wxdatetime.html

Thanks Cody, I'm now using this :

my_date = self.date.GetValue()
isodate = my_date.FormatISODate()

and of course, it works.

One thing I'm stumped on, is getting time. wx doesn't seem to have
the same sort of chooser for time as it has for dates, I've found the
masked.timectrl() widget, but it returns a string of the format
HH:MM:SS (AM|PM) which isn't a format that MySQL can use as a time.
I'm trying to get user input to choose a date and a time from a form,
defaulting to now. wx.DatePickerCtrl() doesn't seem to present a time
option (although it returns DateTime but with a time of 00:00:00),
which would probably be the ideal if it did. Any suggestions for the
best widget to use for this?

Thanks again!

Carl



>
> Cody

Bleve

unread,
May 29, 2010, 8:08:45 PM5/29/10
to wxPython-users

Replying to my own question, after digging around in the demo code :

self.startTime = masked.TimeCtrl(self, -1)

.
.
.

start_time = self.startTime.GetWxDateTime()
isotime = start_time.FormatISOTime()

Excellent :)
Reply all
Reply to author
Forward
0 new messages