Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql date format regarding to a specific country

I used MySQL function DATE_FORMAT(table.field, '%d %b %Y'), where the first parameter is my column, and the second is a pattern to format the column according to a date logic.

The output of this function is in english :

10 Feb 2014

And I would like to set the locale language to fr_FR which would output this correct string :

10 Fév 2014

Question : How to change locale language of the DataBase right before the query (in order to change it according to another language) ?

like image 637
Anwar Avatar asked Nov 03 '15 13:11

Anwar


People also ask

What is the correct format of date in MySQL?

MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' .

How do I change date format from YYYY-MM-DD in MySQL?

MySQL uses yyyy-mm-dd format for storing a date value. This format is fixed and it is not possible to change it. For example, you may prefer to use mm-dd-yyyy format but you can't. Instead, you follow the standard date format and use the DATE_FORMAT function to format the date the way you want.

How can we enter dates in MySQL?

MySQL comes with the following data types for storing a date or a date/time value in the database: DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS.


Video Answer


1 Answers

you need to set the correct language setting in the MySQL Server. Look here: MySQL DATE_FORMAT() function

The language used for day and month names and abbreviations is controlled by the value of the lc_time_names system variable (Section 10.7, “MySQL Server Locale Support”).

Run this before your query:

SET lc_time_names = 'fr_FR';

Then set it back to the original value of lc_time_names;

like image 198
Yasen Zhelev Avatar answered Sep 25 '22 00:09

Yasen Zhelev