How to get the first day of preceding month

  • I need to get the first day of the followingmonth.How is it possible.I am unable to find a way to proceed

    i.e my output should be like this

    Scenario 1:

    Input-2012/01/29

    Output-2012/02/01

    Scenario 2:

    Input-2012/12/29

    output-2013/01/01

    I need to accumlate both the scenarios in same coding

    Please guide me in solving this.

    Thanks in advance

  • I can't really see what this has to do with SSIS, but here's one way.

    declare @MyDate datetime

    set @MyDate = '2012-12-29'

    select DATEADD(dd, - (DAY(DATEADD(mm, 1, @MyDate )) - 1), DATEADD(mm, 1, @MyDate ))

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Here is an example query to do it

    Declare @day date

    set @day = '2012/01/29'

    select @day

    Select DAY(@day) as Noofdays

    SELECT DATEADD(mm,1,DATEADD(dd,-(DAY(@day)-1),@day)) AS Day

    Select DATEADD(yy,1,DATEADD(dd,-(DAY(@day)-1),@day)) as Day

  • Using T-SQL:

    declare @MyDate datetime;

    set @MyDate = '20121229';

    select dateadd(mm, datediff(mm,cast('19000101' as datetime),@MyDate) + 1, cast('19000101' as datetime)), @MyDate;

  • I have to work on SSIS to get the first day of following month and the output should be as string value.

    Input:getdate()

    Output:Firstday of the following month

    format of output is=yyyymmdd

    Sorry for not providing the perfect information in the previous post.

Viewing 5 posts - 1 through 4 (of 4 total)

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