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
dim_date
. So your resulting
date
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
date_purchase
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
date_purchase
, 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.