Get the last day of the month in SQL

后端 未结 20 2207
借酒劲吻你
借酒劲吻你 2020-11-27 04:49

I need to get the last day of the month given as a date in SQL. If I have the first day of the month, I can do something like this:

DATEADD(DAY, DATEADD(MONT         


        
20条回答
  •  伪装坚强ぢ
    2020-11-27 05:02

    For SQL server 2012 or above use EOMONTH to get the last date of month

    SQL query to display end date of current month

    DECLARE @currentDate DATE = GETDATE()
    SELECT EOMONTH (@currentDate) AS CurrentMonthED
    

    SQL query to display end date of Next month

    DECLARE @currentDate DATE = GETDATE()
    SELECT EOMONTH (@currentDate, 1 ) AS NextMonthED
    

提交回复
热议问题