Is It Possible to show date if user specify the start date and then in text box user specify the number of month. then the date should be print like :

ex :
user give date 1/1/2011

In text box he enter 10 month

then output will be like

1/1/2011
1/2/2011
1/3/2011
1/4/2011
1/5/2011
1/6/2011
1/7/2011
1/8/2011
1/9/2011
1/10/2011

I am using C# windows application.
I want to show this in crystal report if it is possible.

other wise

in datagridview.......

This gave me the output you wanted:

class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("Input start date:");
            DateTime st = new DateTime(2011,1,1);
            //st = Convert.ToDateTime(Console.ReadLine());
            Console.WriteLine("Input number of months:");
            int nm = Convert.ToInt32(Console.ReadLine());
            // Hey, no error checking here! You normally should.
            for (int i = 0; i < nm; i++)
            {
                Console.WriteLine(st);
                st = new DateTime(st.Year, st.Month + 1,st.Day);
            }
            Console.ReadLine();
        }
    }

But, strange... the AddMonths method or adding simply a month does not seem to work on my machine...

AddMonths is working fine here. A common belief is that it changes the object you are using, when it does not.

using System;

namespace Text {
    class Program {
        static void Main() {
            DateTime dt = new DateTime(2010, 1, 1);
            DateTime next;

            for (int i = 0; i < 10; i++) {
                next = dt.AddMonths(i);
                Console.WriteLine("{0}", next);
            }

           Console.ReadLine();
        }
     }
}
commented: Thanks for augmenting my knowledge! +8

@Momerath: Thanks for this!!!

Thanks for reply..

But I am working inwindows application and i want to show this output in crystal report..

how can i use this code in crystal report (windows application).

If you know the code please tell me.....................

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.