Skip to content
Advertisement

MONTHNAME in Portuguese MYSQL

I´ve got a huge query (In a PHP file) that gives me a monthname from some dates:

CASE A.STATUS
WHEN 'Cancel' THEN LEFT(MONTHNAME(DT_CANCEL),3)
WHEN 'About to cancel' THEN LEFT(MONTHNAME(DATA_REGISTER),3)

END AS MONTH_CANCEL,

Is there a way to insert my language inline with MONTHANAME?

Something like:

WHEN 'Cancel' THEN SET LANGUAGE Portuguese LEFT(MONTHNAME(DT_CANCEL),3)

I don´t want to write case for eveymonth to transform ‘Dec’ to ‘Dez’ and so on, this will take too long.

Advertisement

Answer

Unfortunately in MySQL this cannot be done dynamically within a query.

From the documentation :

The language used for the month name is controlled by the lc_time_names system variable.

You need a separate SQL command to change the setting :

SET lc_time_names = 'pt_PT';
SELECT MONTHNAME('2018-12-28') AS 'Month';

The value of the lc_time_names persists for the lifetime of the MySQL session.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement