It may not matter to you, but I wouldn't have thought this would be a very efficient query, because the database is going to have to call the DATE_FORMAT function twice for every row in your table. I would have thought a more efficient version would be one that asks for all rows between the first of one month and the first of another month (especially if the date column is indexed).
Something like: from datetime import date session.query(List).filter( and_(List.expire >= date(2007, 12, 1), List.expire < date(2008, 1, 1)) ).all() Adding one month to a date is pretty easy, but if you wanted to do any more complicated date calculations, the dateutil library is very good: http://labix.org/python-dateutil Hope that helps, Simon > -----Original Message----- > From: sqlalchemy@googlegroups.com > [mailto:[EMAIL PROTECTED] On Behalf Of Adam B > Sent: 10 December 2007 19:15 > To: sqlalchemy > Subject: [sqlalchemy] Re: Matching a DateTime-field > > > Hello! > > Thanks for the pointers. > > Here is the solution for MySQL : > session.query(List).filter(and_(func.DATE_FORMAT(List.expire,'%Y') > ==2007 ,func.DATE_FORMAT(List.expire,"%m") == 12)).all() > > > > > > On Dec 10, 6:08 pm, "Rick Morrison" <[EMAIL PROTECTED]> wrote: > > Yeah, it was a "for instance" answer, you'll need to use > the correct MySql > > syntax of course. > > > > On 12/10/07, Adam B <[EMAIL PROTECTED]> wrote: > > > > > > > > > On Dec 10, 1:16 am, "Rick Morrison" > <[EMAIL PROTECTED]> wrote: > > > > Any query using sql expressions is going to want to use > correctly typed > > > data > > > > -- you're trying to query a date column with a string > value. The LIKE > > > > operator is for string data. > > > > > > I'm not up on my mssql date expressions, but the answer > is going to > > > resemble > > > > something like this: > > > > > > .........filter(and_(func.datepart('year', List.expire) == 2007, > > > > func.datepart('month', List.expire) == the_month_number)) > > > > > Ok, isnt this mssql specifik? I only find datepart in various > > > VB / .net documentation/solutions. > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---