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

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

Hi,

···

On Fri, May 28, 2010 at 7:50 AM, Bleve <carl.i.brewer@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

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

···

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

Cody

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