I have not used SQLAlchemy (I just use sqlite3 in my projects). It seems to me that SQLAlchemy is a python layer on top of a number of database implementations or “dialects”. I would have assumed that its API would expect
datetime.date objects for dates, irrespective of how any dialect stores them.
Have you tried converting the
wx.DateTime object returned by the
DatePickerCtrl into a
datetime.date object and passing the result to SQLAlchemy?
I use the following function to convert
wx.DateTime objects into
"""Convert a wx.DateTime to a datetime.date.
:param wx_datetime: a wx.DateTime object.
:raise: ValueError, if the date is not valid.
:return: a datetime.date object.
assert isinstance(wx_datetime, wx.DateTime)
ymd = map(int, wx_datetime.FormatISODate().split('-'))
raise ValueError("Invalid date")
wx_dt = wx.DateTime.Now()
py_date = wxDateTime2PyDate(wx_dt)
<class 'wx._core.DateTime'> Thu Apr 6 10:53:05 2023
<class 'datetime.date'> 2023-04-06
However, if the SQLAlchemy API really does expect dates to be passed as strings, then you would need to know what format it expects. If it expects the
ISO 8601 format
"YYYY-MM-DD", then you could just call the