How do I set first day of the week to Monday when using Week(Date) in PHP/MySQL?

前端 未结 2 1754
自闭症患者
自闭症患者 2021-01-22 19:38

I am using the following code to build a Google Chart, to pull in all of entries in a MySQL table corresponding to the Week Numbers in a year. At the moment the Week Numbers st

2条回答
  •  再見小時候
    2021-01-22 20:05

    For it to work in your code, you should be able to change the query to:

    "SELECT Sum(Due) FROM patient_sessions WHERE Type='Session' AND Week(Date,1)=$i"
    

    However, I think I could go one step further and use the GROUP BY to make one sql call, and then iterate over the results;

    "SELECT Week(Date,1), SUM(DUE) FROM patient_sessions WHERE Type='Session' GROUP BY Week(Date,1)"
    

    Alternatively, you might need to use WEEK(Date,2) depending on how you want to handle weeks that span between years.

提交回复
热议问题