How to iterate the time of a DateTime in C #?

0

How can I go iterating the time of a DateTime.

DateTime horaseleccionada = Convert.ToDateTime("10:00:00");

DateTime horactual = horaseleccionada;

for (int i = 0; i < llegada.Length; i++)
{
    DateTime horaconvertida = horactual.AddMinutes(llegada[i]);
    dataGridView1.Rows[i].Cells[2].Value = horaconvertida.ToString("HH:mm:ss");
    horaseleccionada = horaconvertida;
}

The first time the time has a value of 10:00:00 but once it enters the array this adds 30 minutes which is equal to 10:30:00 .
I need to know how I can make the value of horaseleccionada now be 10:30:00 . I hope you have given me to understand, thank you very much.

    
asked by tecch5510 09.12.2018 в 17:25
source

1 answer

0

To iterate over a range of dates the while

is used
DateTime horainicio = Convert.ToDateTime("10:00:00");

DateTime horafil = llegada;

int i = 0;
while (horainicio < llegada)
{
    dataGridView1.Rows[i].Cells[2].Value = horainicio.ToString("HH:mm:ss");
    horainicio = horainicio.AddMinutes(30);
    i++;
}

As you will see in each iteration, the 30 min is added up to the final date

If you have an array with the munitus you would use

foreach (int i = 0; i < llegada.Length; i++)
{
    horactual = horactual.AddMinutes(llegada[i]);
    dataGridView1.Rows[i].Cells[2].Value = horactual.ToString("HH:mm:ss");
}
    
answered by 09.12.2018 / 20:37
source