You must Sign In to post a response.
  • Category: SQL Server

    How can we find Last day of Month ?

    How can we find last Day of the month ?

    e.g 31 May 2010
    day is monday
  • #505014
    Create function [dbo].[LastDateOfCurrentMonth](@Year int, @Month int)
    -- returns a datetime value for the specified year, month and day
    -- Thank you to Michael Valentine Jones for this formula (see comments).
    returns datetime
    as
    begin
    return DateAdd(day, -1, DateAdd(month, DateDiff(month, 0, CONVERT(DATETIME, CONVERT(char(2), @Month) + '/01/' + CONVERT(char(4), @year)))+1, 0))
    end

    Then Call this like as bellw any where :
    Select dbo.LastDateOfCurrentMonth(2010,3)

    BR,

    RK.

  • #505018
    Hi

    Please check this query:

    SELECT DATENAME(dw, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)))

    Thanks & Regards
    Paritosh Mohapatra


    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #505036
    http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.