Getting Year & Date inside wpdb [duplicate]

You mention the Codex page for WP_Query but you are not using WP_Query. You are using wpdb.

WP_Query is a very complicated class for querying the WordPress tables for post (CPT) data. wpdb is a lightweight wrapper around PHP SQL functions. With WP_Query you can pass arguments like monthnum because the WP_Query class converts the argument into proper SQL.

With wpdb you have to write the SQL. $wpdb->get_results essentially passes your SQL through to the database engine. If you look at the database descriptions, there is no column named monthnum. You are asking MySQL to pull data from a column that does not exist. That is why you get an error.

You need to write valid SQL– look at the date manipulation functions— or use WP_Query whose Codex page you are already investigating. The latter is the better choice.

error code: 523