How to get first day of every corresponding month in mysql?

后端 未结 13 1848
野的像风
野的像风 2020-11-27 18:03

I want to get first day of every corresponding month of current year. For example, if user selects \'2010-06-15\', query demands to run from \'2010-06-01\' instead of \'2010

13条回答
  •  一整个雨季
    2020-11-27 19:03

    I'm surprised no one has proposed something akin to this (I do not know how performant it is):

    CONCAT_WS('-', YEAR(CURDATE()), MONTH(CURDATE()), '1')
    

    Additional date operations could be performed to remove formatting, if necessary

提交回复
热议问题