SQL Query to find the last day of the month

前端 未结 14 1774
太阳男子
太阳男子 2020-11-27 04:40

I need to find the last day of a month in the following format:

\"2013-05-31 00:00:00:000\"

Anybody please help out.

14条回答
  •  暖寄归人
    2020-11-27 05:12

    I know this question was for SQL Server 2005, but I thought I'd mention- as of SQL 2012, there now is an EOMONTH() function that gets the last day of the month. To get it in the format specified by the original asker you'd have to cast to a datetime.

    SELECT CAST(eomonth(GETDATE()) AS datetime)
    

提交回复
热议问题