FOR cycle to add non-existent dates

1

I have the following cycle for to recover from 0 to 24 hours of a data converted to string in which the elements that do not exist add them to me but I also want to do it with the dates, the problem is not to pass the data to string but to identify what day and year you should have in a time range.

for (int ii = 0; ii <= 24; ii++)
        {
            DataRow[] dr = rs.Tables[0].Select("HOURS = " + (ii < 10 ? "0" : "") + ii.ToString());
            if (dr.Length == 0)
            {
                DataRow drnew = rs.Tables[0].NewRow();
                rs.Tables[0].Rows.Add((ii < 10 ? "0" : "") + ii.ToString() + ":00:00");
            }
        }
    
asked by Cris Valdez 10.10.2016 в 20:04
source

1 answer

1

As I understand it, you want to go from a date to a date b day by day, without having to call 3 'for's and go checking days of the month, etc.

Interestingly, this works:

DateTime fechaInicial = //Fecha Inicio
DateTime fechaFinal = //Fecha Fin

for (DateTime d = fechaInicial; d <= fechaFinal; d = d.AddDays(1))
{
    //Hacer algo con la fecha
}
    
answered by 11.10.2016 в 20:27