What is the equivalent of Oracle's LAST_DAY() function in SQL Server 2008?
问题 I have used the LAST_DAY() function in Oracle like this: Last_Day( to_date( '$pay_first_day' , 'YYYY-mm-dd') ) What do i have to do in SQL server 2008 R2 database to achieve the same result? 回答1: Try this one - DECLARE @Date DATETIME SELECT @Date = GETDATE() SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, @Date) + 1, 0) - 1 回答2: -- Wrapping the answer in a function for seamless transition. CREATE FUNCTION [dbo].[LAST_DAY] ( @inDate DATETIME ) RETURNS DATETIME AS BEGIN RETURN DATEADD(MONTH, DATEDIFF