Mysql
 sql >> Base de données >  >> RDS >> Mysql

affichage de la semaine selon la date

Au lieu d'utiliser WEEKDAY, utilisez WEEKOFYEAR

SELECT WEEKOFYEAR(date) AS week, date
FROM myTable
WHERE date BETWEEN start_date AND end_date
ORDER BY week

MISE À JOUR Cette question est la source

SELECT  (WEEK(date, 5) -
        WEEK(DATE_SUB(date, INTERVAL DAYOFMONTH(date) - 1 DAY), 5) + 1) as week, date
    FROM myTable
    WHERE date BETWEEN start_date AND end_date
    ORDER BY week

MISE À JOUR 2

SELECT  (WEEK(date, 1) -
        WEEK(DATE_SUB(date, INTERVAL DAYOFMONTH(date) - 1 DAY), 1) + 1) as week, date
    FROM myTable
    WHERE date BETWEEN start_date AND end_date
    ORDER BY week