How can I cast a date or timestamp column to date within a to_char function?
to_char(date_column, 'YYYY'-'MM) as year_month_col
But I need to cast the date_column to date first but am unsure
Thanks
CodePudding user response:
TO_CHAR
, as you are using it above, appears to be Oracle code. MySQL uses the DATE_FORMAT
function:
SELECT DATE_FORMAT(date_column, '%Y-%m') AS year_month_col
FROM yourTable;