how to find out number of days in month in mysql

前端 未结 7 2020
北恋
北恋 2020-12-14 15:18

I have several dates in mysql tables, using those dates I need to find out the number of days in the month. Suppose i have 2003-02-05 it should return 28. for example

<
7条回答
  •  温柔的废话
    2020-12-14 15:40

    I think you are asking the total number of days to be returned for a month. If you are trying to find the total number of days for current month, here is the query:

    select timestampdiff(day,
    concat(year(now()),'-',month(now()),'-01'),
    date_add( concat(year(now()),'-',month(now()),'-01'), interval 1 month)).
    

    If you want to externalize this using any programming language, externalize year and month in the code and replace that with now()

提交回复
热议问题