It depends on which database you’re using, and which module you are
using to access that database. Usually, you shouldn’t be converting the date to a string. The
conversion to string depends on the country settings of the computer
being used, and probably don’t match your database. You’ll want to
leave it as a date/time object. The database adapters can then
convert it:
cursor.execute( “SELECT e.name, e.surname FROM work w JOIN
employ e ON e.idZ=w.employ_idZ”
“WHERE work.dateFrom >= ? AND work.dateToDo <= ?;”,
(startDate, EndDate) )
However, there’s still probably a conversion required. The
datepicker GetValue returns a wx.DateTime, which isn’t going to be
recognized by the database adapters. If the adapter wants a Python
datetime, you’ll have to convert it. For example:
import datetime
startD1 = datetime.datetime.fromtimestamp( startDate.GetTicks()
)
endD1 = datetime.datetime.fromtimestamp( endDate.GetTicks() )
If you’re using sqlite, then there are other considerations. Sqlite
doesn’t have types, so everything is a string. In that case, you
just need to format your dates into whatever format you want to use
in the database.
···
Ja M wrote:
I want to create a query that will
extract data between
two given dates.
Dates are given
in datepicker
datepickers:
startDate =
str(self.datepicker_ctrl_1.GetValue ())
EndDate =
str(self.datepicker_ctrl_2.GetValue ())
query
SELECT employ.name, employ.surname FROM work JOIN employ
ON employ.idZ=work.employ_idZ WHERE work.dateFrom>=
‘??’ AND work.dateToDO<= ‘??’