Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql week from Monday till Sunday

Tags:

mysql

i want to group my data by yearweek but the week starts here in sunday. how can i group my week from monday till sunday?

Here is my query:

SELECT YEARWEEK(dateStats) k,dateStats udate, COUNT(f_shop) sales
FROM sal_import WHERE dateStats BETWEEN "2011-08-15" AND "2011-08-21" GROUP BY YEARWEEK(dateStats)

The Between has a date from Monday till Sunday and i need just one row at the result.

Thank you very much

like image 912
user954740 Avatar asked Oct 27 '11 10:10

user954740


People also ask

How to get week from date in MySQL?

MySQL WEEK() Function The WEEK() function returns the week number for a given date (a number from 0 to 53).

How to get Sunday date in MySQL?

MySQL WEEKDAY() Function The WEEKDAY() function returns the weekday number for a given date. Note: 0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday.

What is interval in MySQL?

MySQL interval is an operator, which is based on the binary search algorithm to search the items and returns the value from 0 to N. It is mainly used to calculate the date and time values. We can use the following syntax to create an interval value: INTERVAL expr unit.

How to get day number in MySQL?

MySQL DAY() function MySQL DAY() returns the day of the month for a specified date. The day returned will be within the range of 1 to 31. If the given date is '0000-00-00', the function will return 0. The DAYOFMONTH() is the synonym of DAY().


1 Answers

Second argument of YEARWEEK(date[,mode]) function is mode - like in WEEK(date[,mode]) function.

You can specify start day - default is 0 (Sunday).

Just set it to 1 (Monday):

YEARWEEK(dateStats, 1)
like image 194
hsz Avatar answered Oct 12 '22 00:10

hsz