TSQL DATEADD Help

  • I have the following:

    DECLARE @StartInsertedDate DATETIME

    SET @StartInsertedDate = CAST(CONVERT(VARCHAR(10), DATEADD(MONTH, -18,GETDATE()) - 1, 101) AS DATETIME) --DATEADD(DAY, -1, DATEDIFF(DAY, 0, GETDATE()))

    SELECT @StartInsertedDate

    AND it returns 2011-11-16 00:00:00.000

    I want it to return the 1st day of the month (2011-11-01 00:00:00.000 is what I want) and I can not get it to for the life of me.

    Any help will be greatly appreciated.

  • I give up too easily and over complicate things, I believe I have what I need below:

    SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 18, 0)

    Thanks

  • GBeezy (5/17/2013)


    I give up too easily and over complicate things, I believe I have what I need below:

    SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 18, 0)

    Thanks

    Or this:

    select datadd(month, datediff(month,0,getdate()), 0)

    You may want to check out this:

    http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply