You have the following code:
date = cursor.execute("""SELECT *, MONTH (STR_TO_DATE(date_purchase, '%m/%d/%Y' )) FROM dim_date""")
date_month = str(date)
Your SELECT statement should return all columns from every record in
. So your resulting
field will not be a month number.
To be honest, I cannot work out what you are trying to do with this code, as it looks like random statements.
You start with
so it is a simple matter to extract the month from that, without going to the database. If you want to find any record that was inserted with that value of
, then you just need something like:
date = cursor.execute("SELECT * FROM dim_date WHERE purchase_date = " + date_purchase + ";")
But this is largely guesswork as I do not know the structure of your database table.