I need to compare two date, in case the conversion of the String field to DateTime is giving error, because as mentioned above the field is being modified at the time it passes in the foreach.
Here is the code in PageModel:
var tp = _context.TarifasPrecosItens.Where(p => p.TarifasPrecosId == tx.Id).First();
foreach(var hora in tp.De)
{
DateTime horaInicial = Convert.ToDateTime(hora);
DateTime horaCliente = Convert.ToDateTime(totalPermanencia);
if (horaCliente > horaInicial)
{
PagamentoTarifaUsada = tx.Descricao + " Acima de " + hora;
Tarifa = tp.Valor;
Total = tp.Valor;
}
}