-3
Consider an informed date in a form. Construct a function that checks if the date is correct (considering leap year, April 31, etc.). You need to pass the date entered in the form as a parameter.
If the date is correct, construct another function that will count the days from the beginning of the year to the informed date. Again passing the date as parameter. For example, how many days is 12/09/2015? Answer 258.
The rest I did, I’m just not getting this day count.
This is all being done in C# with Windows Forms:
private void btnVerificar_Click(object sender, EventArgs e)
{
int iDia = Convert.ToInt32(txtDia.Text);
int iMes = Convert.ToInt32(txtMes.Text);
int iAno = Convert.ToInt32(txtAno.Text);
VerificaAno(iAno);
int iData = Convert.ToInt32(DateTime.Now.Year);
VerificaData(iDia, iMes, iAno);
int iTotalDias = Convert.ToInt32(DateTime.Now.Year);
ContarDias(iDia, iMes, iAno, iData);
}
private void VerificaData(int iDia, int iMes, int iAno)
{
int iData = DateTime.DaysInMonth(iAno, iMes);
if (iDia > iData || iDia < 1)
{
lblData.Text = "DATA INVÁLIDA";
lblData.ForeColor = System.Drawing.Color.Red;
}
else
{
lblData.Text = "DATA VÁLIDA";
lblData.ForeColor = System.Drawing.Color.Blue;
}
}
private void ContarDias(int iDia, int iMes, int iAno, int iData)
{
#####NO CASO SERIA AQUI QUE EU IRIA FAZER O MEU CÓDIGO#####
}
private void VerificaAno(int iAno)
{
if (((iAno % 400) == 0) || (iAno % 4 == 0 && iAno % 100 != 0))
{
lblAnoBissexto.Text = "ANO BISSEXTO";
}
else
{
lblAnoBissexto.Text = "ANO NÃO BISSEXTO";
}
}
Is there a problem, or what is the purpose of the question? If possible, make it clearer what you want to do and improve the formatting of the question
– Grupo CDS Informática
The question is old, but a detail that was not put in the answers: to know how many days have passed since the beginning of the year, you can use
new DateTime(ano, mes, dia).DayOfYear
- the difference is thatDayOfYear
also counts the day 1 of January. It is already calculated the difference, as they did in the answers, does not count (but then it would be enough to subtract 1)– hkotsubo