Get the first and last date of next month in MySQL

后端 未结 11 1140
感情败类
感情败类 2020-12-01 03:43

How can I get the first and last day of next month to be used in the where clause?

11条回答
  •  我在风中等你
    2020-12-01 04:18

    Use:

    SELECT
    
    DATE_SUB(
        LAST_DAY(
            DATE_ADD(NOW(), INTERVAL 1 MONTH)
        ), 
        INTERVAL DAY(
            LAST_DAY(
                DATE_ADD(NOW(), INTERVAL 1 MONTH)
            )
        )-1 DAY
    ) AS firstOfNextMonth,
    
    LAST_DAY(
        DATE_ADD(NOW(), INTERVAL 1 MONTH)
    )AS lastOfNextMonth
    

提交回复
热议问题