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

后端 未结 13 1885
野的像风
野的像风 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 18:53

    This works fine for me.

     date(SUBDATE("Added Time", INTERVAL (day("Added Time") -1) day))
    

    ** replace "Added Time" with column name

    Use Cases:

    1. If you want to reset all date fields except Month and Year.

    2. If you want to retain the column format as "date". (not as "text" or "number")

提交回复
热议问题