how can i find number of days in a given year and month
-
how can i find number of days in a given year and month
-
how can i find number of days in a given year and month
Number of days in a year is a constant (varies for a leap year). Number of days in any given month is going to be a constant (except for February in a leap year). Which part of this are you having a difficulty with?
It is a crappy thing, but it's life -^ Carlo Pallini
-
Number of days in a year is a constant (varies for a leap year). Number of days in any given month is going to be a constant (except for February in a leap year). Which part of this are you having a difficulty with?
It is a crappy thing, but it's life -^ Carlo Pallini
thank you for your replay and you solved the problem and i remembered that if we want to know if February in a leap year or not by divided the year by 4 and if the result is an integer number it will be leap year such as 2004/4=501 this is a leap year and 2005/4=501.25 it's not a leap year and i'll to try it by code Many thanks for all
modified on Tuesday, June 2, 2009 3:48 AM
-
thank you for your replay and you solved the problem and i remembered that if we want to know if February in a leap year or not by divided the year by 4 and if the result is an integer number it will be leap year such as 2004/4=501 this is a leap year and 2005/4=501.25 it's not a leap year and i'll to try it by code Many thanks for all
modified on Tuesday, June 2, 2009 3:48 AM
Ooh - not quite. If it's a century, it has to be divisible by 400 to be a leap year, so 2000 is a leap year and 2100 isn't.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
thank you for your replay and you solved the problem and i remembered that if we want to know if February in a leap year or not by divided the year by 4 and if the result is an integer number it will be leap year such as 2004/4=501 this is a leap year and 2005/4=501.25 it's not a leap year and i'll to try it by code Many thanks for all
modified on Tuesday, June 2, 2009 3:48 AM
-
Ooh - not quite. If it's a century, it has to be divisible by 400 to be a leap year, so 2000 is a leap year and 2100 isn't.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Let us hope that his code will not have to run for a century. :)
It is a crappy thing, but it's life -^ Carlo Pallini
-
Ooh - not quite. If it's a century, it has to be divisible by 400 to be a leap year, so 2000 is a leap year and 2100 isn't.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
use modulus (provides the remainder after a division) not divide...
if(year % 4 == 0)
//is leap year
else
//not leap yearLife goes very fast. Tomorrow, today is already yesterday.
Many Thanks and i'm very happy from Your cooperation
-
is 2100 really not a leap year? EDIT: It's OK I WIKI it and got an answer ;)
Life goes very fast. Tomorrow, today is already yesterday.
i dont think
-
how can i find number of days in a given year and month
-
i don't know if the user will enter 2009 or 2008 or any month i want to take the data from the user
modified on Tuesday, June 2, 2009 4:19 AM
-
Many Thanks and i'm very happy from Your cooperation
-
Ok this is what you should use instead...
if(year % 4 == 0 && year % 100 == 0 ? year % 400 == 0 : true)//hope you get that logic
//is leap year
else
//not leap yearLife goes very fast. Tomorrow, today is already yesterday.
you realy have come to the right solution thank you
-
i don't know if the user will enter 2009 or 2008 or any month i want to take the data from the user
modified on Tuesday, June 2, 2009 4:19 AM
-
Ok this is what you should use instead...
if(year % 4 == 0 && year % 100 == 0 ? year % 400 == 0 : true)//hope you get that logic
//is leap year
else
//not leap yearLife goes very fast. Tomorrow, today is already yesterday.
-
Or if you don't want to reinvent the wheel:
if (DateTime.IsLeapYear(year)) {
// is leap year
} else {
// not leap year
};)
Despite everything, the person most likely to be fooling you next is yourself.
-
how can i find number of days in a given year and month
i finished simple code for this topic and i want you to review it sory for not optimized code but see the idea download the project: http://www.geocities.com/ahmed_117/Month.zip[^]
-
i finished simple code for this topic and i want you to review it sory for not optimized code but see the idea download the project: http://www.geocities.com/ahmed_117/Month.zip[^]
Have a look at this:
private void button1_Click(object sender, EventArgs e) {
button1.Enabled = false;
int year = dateTimePicker1.Value.Year;
int month = dateTimePicker1.Value.Month;
DateTime start = new DateTime(year, month, 1);
dateTimePicker1.Value = start;
int days = DateTime.DaysInMonth(year, month);
for (int i = 0; i < days; i++) {
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = start.AddDays(i).DayOfWeek;
dataGridView1.Rows[i].Cells[1].Value = start.AddDays(i).ToShortDateString();
}
}Despite everything, the person most likely to be fooling you next is yourself.
-
Have a look at this:
private void button1_Click(object sender, EventArgs e) {
button1.Enabled = false;
int year = dateTimePicker1.Value.Year;
int month = dateTimePicker1.Value.Month;
DateTime start = new DateTime(year, month, 1);
dateTimePicker1.Value = start;
int days = DateTime.DaysInMonth(year, month);
for (int i = 0; i < days; i++) {
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = start.AddDays(i).DayOfWeek;
dataGridView1.Rows[i].Cells[1].Value = start.AddDays(i).ToShortDateString();
}
}Despite everything, the person most likely to be fooling you next is yourself.
a very Clever man this what i want to reach thank you