Mysql WEEKDAY() vs Mysql DayofWeek()
WEEKDAY() returns an index from 0 to 6 for Monday to Sunday
DAYOFWEEK() returns an index from 1 to 7 for Sunday to Saturday
So, the same day has different indexes, eg. Sunday can be 1 or 6
Often I prefer to use DAYOFWEEK()
because SQL functions like ELT() are 1-index based :
SELECT ELT(DAYOFWEEK(NOW()), 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
SELECT ELT(WEEKDAY(NOW()) + 1, 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
A relevant difference is that weekday counts the days of the week from Monday, as follows and start from 0
0=Monday, 1=Tuesday, 2=Wednesday, 3=Thursday, 4=Friday, 5=Saturday, 6=Sunday
On the other hand dayofweek counts the days of the week from Sunday and start with 1
1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday
Please try
select weekday(now()) weekday, dayofweek(now()) dayofweek;