Count days of the month

Hello,

i have just made a simple program it ask for a date and it cheks for a leap year,

the second thing i  like this program to do is, to show the day number in the given date. so for example if the given date is  10/1/2010    i should say the date is its the 10th day day of the year ...

but i dont know how to do this anyone help me please??
i have upload the program.
thank you
ConsAppl1TI24.zip
kensy11Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

santhimurthydCommented:
Below Code will help
DateTime dt = DateTime.ParseExact(@"10\1\2010" , @"dd\MM\yyyy" , null);
int dayofYear = dt.DayOfYear;

0
pivarCommented:
Hi,

You could use the DateTime.DayOfYear property.

http://msdn.microsoft.com/en-us/library/system.datetime.dayofyear.aspx

/peter
0
kensy11Author Commented:
thanks , but how can i dot it manually i mean without the DateTime property
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

kensy11Author Commented:
something like this??

ushort totaal;
        ushort m1 = 31;
        ushort m2 = 28;
        ushort m3 = 31;
        ushort m4 = 30;
        ushort m5 = 31;
        ushort m6 = 30;
        ushort m7 = 31;
        ushort m8 = 31;
        ushort m9 = 30;
        ushort m10 = 31;
        ushort m11 = 30;
        ushort m12 = 31;
        switch (Maand) {

          case 1:
                  totaal += m1;
                  break;
          case 2:
                  totaal +=(m1+m2);
                  if(ctrl.Jaar(jaar))
                     totaal +=1;
                  break;
          case 3:
                totaal +=(m1+m2+m3);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 4:
                totaal +=(m1+m2+m3+m4);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 5:
                totaal +=(m1+m2+m3+m4+m5);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 6:
                totaal +=(m1+m2+m3+m4+m5+m6);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 7:
                totaal +=(m1+m2+m3+m4+m5+m6+m7);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 8:
               totaal +=(1+2+3+4+m5+m6+m7+m8);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 9:
                totaal +=(1+2+3+4+5+6+7+8+9);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 10:
                totaal +=(1+2+3+4+5+6+7+8+9+10);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 11:
               totaal +=(1+2+3+4+5+6+7+8+9+10+11);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;
          case 12:
                totaal +=(1+2+3+4+5+6+7+8+9+10+11+12);
                if(ctrl.Jaar(jaar))
                    totaal +=1;
                break;


        }

Open in new window

0
pivarCommented:
Why without DateTime? Even if you don't have it, I think it's easier to create one than do it yourself.

But if you want to do it yourself, you need an array of days for each month of the year, which you could sum up to previous month plus days of current month. And don't forget to add an extra day if it's a leap year and month > 2.
0
pivarCommented:
I was thinking, something like:

int [] daysinmonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int days = 0;

for(int i = 0; i < yourmonth-1; i++) {
  days += daysinmonth[i];
}

days += yourdayofmonth;

if ((yourmonth > 2) && (youryear % 4 == 0) && ((youryear %100 != 0) || (youryear % 400 == 0))) {
  days++;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.