Home > Software design >  Filter rows from today in MySQL in Python
Filter rows from today in MySQL in Python

Time:12-30

I use this query to filter out rows from different day than today. I need to get only column book_url:

"""
SELECT book_url
FROM KNIHY
WHERE  CAST(KNIHY.scrape_date AS DATE) = CAST( curdate() AS DATE)
"""

where scrape_date has a following form 29/12/2021 07:13:21.

My code fails on mysql.err.ProgrammingError. How can I fix it please?

CodePudding user response:

It appears that you are storing text dates in the scrape_date column. You should instead be using a proper bona fide date column here. In lieu of this, you may try converting the text to date using STR_TO_DATE():

SELECT book_url
FROM KNIHY
WHERE STR_TO_DATE(scrape_date, '%d/%m/%Y') = CURDATE();
  • Related