Hi everyone, I am trying to retrieve deceased persons who died in the current month but the output gives no result. Here is my code with query done in Python Flask:
from datetime import datetime from sqlalchemy import func--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/f6a17840-cdfd-4f26-bdc5-0a75af82fa91n%40googlegroups.com.
--
--
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+...@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+...@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 a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/4oPfuzAjw48/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/87pm8ier3i.fsf%40metapensiero.it.
However, the query gives no events that took place in the current month, yet I have events that indeed took place in April (the current month). The current month is to be automated, which I have successfully accomplished through datetime.today().strftime('%m').
By breaking the query into sections, I was able to know where the problem is. The section of the query: current_user.followed_events().filter(Event.event_date < datetime.today().date())gives all events that have passed (yesterday and beyond). This part works correctly.
The section: current_user.followed_events().filter(Event.event_date < datetime.today().date()).order_by(Event.timestamp.desc())arranges these pasts events in descending order and this section works correctly, as well.
However, the part with problem is: .filter(func.strftime('%m', Event.event_date == datetime.today().strftime('%m')))where the aim is to filter out events that took place in the current month, irrespective of the year they took place.
Note that I have imported the following modules from sqlalchemy import funcand from datetime import datetimeat the top of the routes.py.
The event_date field in the models.py is stored as a db.DateTime with a default = datetime.utcnow. I am using Flask, with SQLite db, but will change it to Postgresql later.
I hope the information is enough, otherwise let me know if additional information is needed.
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CA%2B9bh8dc1ph6UC49pqjVeVfg-DEo%2BE2vFxu0NCXoB9AonsWXtQ%40mail.gmail.com.
However, the query gives no events that took place in the current month, yet I have events that indeed took place in April (the current month). The current month is to be automated, which I have successfully accomplished through datetime.today().strftime('%m').
By breaking the query into sections, I was able to know where the problem is. The section of the query: current_user.followed_events().filter(Event.event_date < datetime.today().date())gives all events that have passed (yesterday and beyond). This part works correctly.
The section: current_user.followed_events().filter(Event.event_date < datetime.today().date()).order_by(Event.timestamp.desc())arranges these past events in descending order and this section works correctly, as well.
However, the part with problem is: .filter(func.strftime('%m', Event.event_date) == datetime.today().strftime('%m'))where the aim is to filter out events that took place in the current month, irrespective of the year they took place.
Note that I have imported the following modules from sqlalchemy import funcand from datetime import datetimeat the top of the routes.py.
The event_date field in the models.py is stored as a db.DateTime with a default = datetime.utcnow. I am using Flask, with SQLite db, but will change it to Postgresql later.
I hope the information is enough, otherwise let me know if additional information is needed.
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CA%2B9bh8dc1ph6UC49pqjVeVfg-DEo%2BE2vFxu0NCXoB9AonsWXtQ%40mail.gmail.com.
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CA%2B9bh8dc1ph6UC49pqjVeVfg-DEo%2BE2vFxu0NCXoB9AonsWXtQ%40mail.gmail.com.