I think that this will solve what you are asking, let me know if I misunderstood what you are looking for.
DECLARE
@numMonthsINT
,@targetDateDATETIME
,@firstDayDATETIME
,@lastDayDATETIME
SELECT @numMonths = 2
SELECT @targetDate = DATEADD(MM, @numMonths * -1,...