Hi Lee, thanks for responding.

The code was only part of the entire query, perhaps I needed to provide the
entire query and try to explain and give an explanation a little bit.
Here is the entire code:
monthly_events = current_user.followed_events().filter(Event.event_date <
datetime.today().date()).filter(func.strftime('%m', Event.event_date =
datetime.today().strftime('%m'))).order_by(Event.timestamp.desc())
The section of the query:
current_user.followed_events().filter(Event.event_date
<= datetime.today().date()) gives all upcoming events that are yet to
happen, including those that are due today. This part works correctly.
The section: current_user.followed_events().filter(Event.event_date <
datetime.today().date()).order_by(Event.timestamp.desc()) arranges the
events in dissenting order and this section works currently for all
upcoming events.
However, the part with problems is this one: .filter(func.strftime('%m',
Event.event_date = datetime.today().strftime('%m'))) where the aim to
filter out events that will take place in the current month. This is the
section that I posted, yet I needed to post the entire query for what I am
intending to achieve is understood.  Note that I have imported the
following modules from sqlalchemy import func and from datetime import
datetime at the top.
The event_date field in the models.py is stored as a db.DateTime with a default
= datetime.utcnow.

On Wed, Apr 5, 2023 at 9:07 AM Lele Gaifax <l...@metapensiero.it> wrote:

> Nancy Andeyo <nandey...@gmail.com> writes:
>
> > the filter *.filter(func.strftime('%m', func.date(Events.date_of_event)
> ==
> > datetime.today().strftime('%m')))* to get all the events that happened in
> > the current month is not working. But displays all the events.
>
> Read carefully what you have written:
>
> > func.strftime('%m', func.date(Events.date_of_event) ==
> datetime.today().strftime('%m'))
>
> You are passing a boolean value to the strftime() function, and that's
> not what you probably meant/want.
>
> ciao, lele.
> --
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
> l...@metapensiero.it  |                 -- Fortunato Depero, 1929.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example.  See  http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/87ttxueubh.fsf%40metapensiero.it
> .
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAJiyv_2aEuJsWOE%2B6cwKFHo_R3zQ6kFF68QzmrQtm4U_pXEPHw%40mail.gmail.com.

Reply via email to