Reputation: 149
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.
Upvotes: 2
Views: 2744
Reputation: 1
I was racking my brain with a chart where the months were in Spanish. Solved my problem.
try{
$conn = new PDO($dsn, DB_USER, DB_PASS, $opt);
$conn->exec("SET lc_time_names = 'pt_BR'");
}catch (PDOException $e) {
print "Error! " . $e->getMessage() . "<br/>";
die();
}
Upvotes: 0
Reputation: 222472
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.
Upvotes: 4
Reputation: 428
Run the following query before you run your query:
SET lc_time_names = 'pt_PT';
Upvotes: 2