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?
 
pivarConnect With a Mentor Commented:
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
 
santhimurthydConnect With a Mentor Commented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
kensy11Author Commented:
thanks , but how can i dot it manually i mean without the DateTime property
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.