-1
I needed this parameter to count the days until the date I type for example (31/12/2016) as shown in the attached image, but it is only returning the number of days that was typed in the case 31 days and not the total of days until that date that in the case would be 366 days. Can anyone give me any hint on how to do this count by returning the total of days until the date typed?
Note: The return of the number of days will be on a label (lblTotalDias.Text)
int iTotal = 0;
if (iDia < iMes)
{
iDia = 0;
iTotal++;
if (iDia < 30)
{
iDia++;
iTotal++;
if (iMes == 2 && ((iAno % 400 == 0)
|| (iAno % 4 == 0 && iAno % 100 != 0)) && iDia == 28)
{
iTotal++;
iDia = 31;
}
if (iMes == 2 && !((iAno % 400 == 0)
|| (iAno % 4 == 0 && iAno % 100 != 0)) && iDia == 27)
{
iTotal++;
iDia = 31;
}
if ((iMes == 1 || iMes == 3 || iMes == 5 || iMes == 7
|| iMes == 8 || iMes == 10 || iMes == 12) && iDia == 30)
{
iDia++;
iTotal++;
}
}
iMes++;
iTotal++;
}
iDia++;
iTotal++;
lblTotalDias.Text = (iDia - 1) + " DIAS";
}
I didn’t understand the criteria that came in 31 days.
– Maniero
It wasn’t supposed to be like this:
lblTotalDias.Text = (iTotal - 1) + " DIAS";
?– isaque
I typed the date 31/12/2016 and in case I was to return the days of the beginning of the year in the case 01/01/2016 until 31/12/2016 that would be 366 days, but he is not returning me the 366 days as I would like and yes only 31 days that was typed I do not know if could understand
– Thiago
@Serve it back to me the 31 days too
– Thiago
was for him to calculate the distance in days from the date typed to today’s date?
– isaque
@Drawing was for him to calculate the total days of the date typed for example 31/12/2016 until the initial date of the beginning of the year that would be 01/01/2016 that would be 366 days
– Thiago
It lacked to say the clear logic, it is very confused, but, it does not need almost anything of code, the structure Datetime already makes much of these calculations
– novic
@Virgilionovic Thanks, I took advantage of the code using some rules of day and month and I used the Datetime ai managed to do the calculation without returning error.
– Thiago