## How to get the first day of preceding month

 Author Message manibad SSC Eights! Group: General Forum Members Points: 807 Visits: 143 I need to get the first day of the followingmonth.How is it possible.I am unable to find a way to proceedi.e my output should be like thisScenario 1:Input-2012/01/29Output-2012/02/01Scenario 2:Input-2012/12/29output-2013/01/01I need to accumlate both the scenarios in same coding Please guide me in solving this.Thanks in advance Phil Parkin SSC Guru Group: General Forum Members Points: 129078 Visits: 22584 I can't really see what this has to do with SSIS, but here's one way.`declare @MyDate datetimeset @MyDate = '2012-12-29'select DATEADD(dd, - (DAY(DATEADD(mm, 1, @MyDate )) - 1), DATEADD(mm, 1, @MyDate ))` Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot. Sachin4all Mr or Mrs. 500 Group: General Forum Members Points: 551 Visits: 314 Here is an example query to do it Declare @day dateset @day = '2012/01/29'select @daySelect DAY(@day) as Noofdays SELECT DATEADD(mm,1,DATEADD(dd,-(DAY(@day)-1),@day)) AS DaySelect DATEADD(yy,1,DATEADD(dd,-(DAY(@day)-1),@day)) as Day Lynn Pettis SSC Guru Group: General Forum Members Points: 225362 Visits: 40420 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;` Lynn PettisFor better assistance in answering your questions, click hereFor tips to get better help with Performance Problems, click hereFor Running Totals and its variations, click here or when working with partitioned tablesFor more about Tally Tables, click hereFor more about Cross Tabs and Pivots, click here and hereManaging Transaction LogsSQL Musings from the Desert Fountain Valley SQL (My Mirror Blog) manibad SSC Eights! Group: General Forum Members Points: 807 Visits: 143 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 monthformat of output is=yyyymmddSorry for not providing the perfect information in the previous post.