How do I get the first day of the week of a date in mysql?

后端 未结 8 1443
猫巷女王i
猫巷女王i 2020-11-30 03:47

Suppose I have 2011-01-03 and I want to get the first of the week, which is sunday, which is 2011-01-02, how do I go about doing that?

The reason is I have this quer

8条回答
  •  Happy的楠姐
    2020-11-30 04:34

    This works form me

    Just make sure both dates in the below query are the same...

    SELECT ('2017-10-07' - INTERVAL WEEKDAY('2017-10-07') Day) As `mondaythisweek`
    

    This query returns: 2017-10-02 which is a monday,

    But if your first day is sunday, then just subtract a day from the result of this and wallah!

提交回复
热议问题