Get the last day of the month in SQL

后端 未结 20 2204
借酒劲吻你
借酒劲吻你 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:08

    Works in SQL server

    Declare @GivenDate datetime
    SET @GivenDate = GETDATE()
    
    Select DATEADD(MM,DATEDIFF(MM, 0, @GivenDate),0) --First day of the month 
    
    Select DATEADD(MM,DATEDIFF(MM, -1, @GivenDate),-1) --Last day of the month
    

提交回复
热议问题