Get the last day of the month in SQL

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

    I know this is a old question but here is another solution that works for me

    SET @dtDate = "your date"
    DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dtDate)+1,0))
    

    And if some one is looking for different examples here is a link http://blog.sqlauthority.com/2007/08/18/sql-server-find-last-day-of-any-month-current-previous-next/

    I hope this helps some one else. stackoverflow Rocks!!!!

提交回复
热议问题