Mysql has a lot of functions to handle dates , it's worth reading the documentation .
You can use the YEAR()
functions for year, MONTH()
for Month, WEEK()
for week and DAYNAME()
for day name, for example:
SET lc_time_names = 'pt_BR';
SET @data = "2014/09/18";
SELECT
YEAR(@data) AS Ano,
MONTH(@data) AS Mês,
WEEK(@data) AS Semana,
DAYNAME(@data) AS Dia_da_Semena
You can also "spike" the string with the date in the call of each of these functions. The disadvantage is that every time you need to change the date, you need to make the change everywhere, as follows:
SET lc_time_names = 'pt_BR';
SELECT
YEAR("2014/09/18") AS Ano,
WEEK("2014/09/18") AS Semana,
MONTH("2014/09/18") AS Mês,
DAYNAME("2014/09/18") AS Dia_da_Semana
NOTE: I needed to add SET lc_time_names = 'pt_BR'
because my MySQL is in English.
SET lc_time_names = 'pt_BR';