Mysql has a large amount of functions to handle dates, is worth a read on documentation.
You can use the functions YEAR()
next year, MONTH()
for the month, WEEK()
next week and DAYNAME()
for the name of the day, 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 "insert" the string with the date in the call of each of these functions. The disadvantage will be that every time you need to change the date, you will need to make the change everywhere, 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';
It worked great here, I’m just having a little problem when the week is the first of January, it returns null
– brunodotcom
I did it, I tweaked the parameters to format and it looked like this:
SELECT str_to_date('201400 Wednesday', '%Y%U %W')
and it worked– brunodotcom