Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have one value no of month.then Insert statment in sql server so i want no of month & year Add

like
no of months = 12
Yearmonth
201512
201601
201602
201603
201604
201605
201606
201607
201608
201609
201610
201611
Posted
Comments
Er. Ajay Chauhan 29-Dec-15 5:41am    
not cleared....
elaborate in brief.....
hemant kolekar 29-Dec-15 6:17am    
sir
I have One text box where enter integer value is month
like 12 is no of month
so i want add in table one column value is Year&month like
201512
201601
201601
201602
201603
201604
201605
201606
201607
201608
201609
201610
201611

because i have pass No of month is 12
Philippe Mori 30-Dec-15 19:09pm    
Update the question instead of rewriting it again.
AshishVishwakarma 29-Dec-15 6:23am    
hemant,
I think simple concatenation may do your job.
and what if input given is 5, it will help to understand problem better
hemant kolekar 29-Dec-15 6:46am    
if input given is 5 then
201512
201601
201602
201603
201604

1 solution

Please check below code:

C#
using System;

public class Program
{
	public static void Main()
	{
		int noOfMonth = 5;
		DateTime currentDate = DateTime.Now;
		for(int i = 0; i < noOfMonth; i++)
		{
   			Console.WriteLine(currentDate.AddMonths(i).ToString("yyyyMM"));
		}
	}

}


Please google first before asking such question.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900