Skip to content
Advertisement

casting date within a to_char function?

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

Advertisement

Answer

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;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement