Click here to Skip to main content
15,904,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
heey all

my question is that i need to get all the days within amonth

(i.e) : when i pass (3,2009) to the function i get aresult like

saturday 1/3/3009
Sunday 2/3/2009
Monday 3/3/2009
------
------
----
------
Friday 31/3/2009


how this should be Done !!!!
Posted

I created a function for you that gives you an array of DateTime values of all days within the month!

C#
public DateTime[] GetAllDays(int year, int month)
{
    int days = DateTime.DaysInMonth(year, month);

    DateTime[] dates = new DateTime[days];

    for (int d = 0; d < days; d++)
    {
        dates[d] = new DateTime(year, month, (d + 1));
    }

    return dates;
}


To use this you should do:

C#
DateTime[] dates = GetAllDays(2009, 3);

for(int d = 0; d < dates.Length; d++)
{
  textBox1.Text += dates[d].ToLongDateString() + Environment.NewLine;
}


Result:
VB
Sunday, March 01, 2009
Monday, March 02, 2009
Tuesday, March 03, 2009
...
...
...
Tuesday, March 31, 2009
 
Share this answer
 
v3
Thank u very much

but how to store this values on datatable column ???
 
Share this answer
 

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