locked
First and last day RRS feed

  • Question

  • How to get first day and last day of month ?
    Saturday, June 20, 2015 6:55 PM

Answers

  • First day 

    select DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+0, 0) 
    

    Last day

    select DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+1, -1)


    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

    • Marked as answer by Tomas85 Saturday, June 20, 2015 7:47 PM
    Saturday, June 20, 2015 7:13 PM
  • DECLARE @mydate DATETIME
    SELECT @mydate = GETDATE()

    SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101) AS Date_Value,
    'First Day of Current Month' AS Date_Type

    UNION
    SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,
    'Last Day of Current Month'

    Please Mark Answer if it solved your issue, Vote As Helpful if it helps to solve your issue


    • Edited by AV111 Saturday, June 20, 2015 7:03 PM
    • Marked as answer by Charlie Liao Thursday, July 9, 2015 1:47 PM
    Saturday, June 20, 2015 7:02 PM

All replies

  • DECLARE @mydate DATETIME
    SELECT @mydate = GETDATE()

    SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101) AS Date_Value,
    'First Day of Current Month' AS Date_Type

    UNION
    SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,
    'Last Day of Current Month'

    Please Mark Answer if it solved your issue, Vote As Helpful if it helps to solve your issue


    • Edited by AV111 Saturday, June 20, 2015 7:03 PM
    • Marked as answer by Charlie Liao Thursday, July 9, 2015 1:47 PM
    Saturday, June 20, 2015 7:02 PM
  • First day 

    select DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+0, 0) 
    

    Last day

    select DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())+1, -1)


    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

    • Marked as answer by Tomas85 Saturday, June 20, 2015 7:47 PM
    Saturday, June 20, 2015 7:13 PM