Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to query database with SQLAlchemy where a date is a particular day of the week?

I have a table (called 'entry') which has a datetime column (called 'access_date'), and I want to do an SQLAlchemy query that only produces results where entry.access_date is a Monday (or any other day of the week specified by a number [0..6]).

Is this possible? I am using sqlite & SQLalchemy 0.5.8 if that makes any difference.

like image 786
Sarah Avatar asked Jul 30 '10 12:07

Sarah


1 Answers

Further from Daniel Kluev's answer, I found another way of saying the same thing (possibly nicer looking?)

query.filter(func.strftime('%w', Entry.access_date) == str(weekday)).all()

Where weekday is a number [0..6]

like image 75
Sarah Avatar answered Sep 25 '22 10:09

Sarah