Format date and time and list according to the current date

5

This application has two tables: Students and Occurrences. To show the occurrences I can calmly ... But now I have a new business rule: Show the occurrences by date. So basically it would be the following, I would have to show the most current occurrences according to the date, that is, if for example I generated an instance yesterday, then it will show it in evidence above the others, but if I generate one today, this of today will have to be in evidence. As for example, what happens here in SOpt. How could I use native C # formatting to show date and time / minutes. That is, I wanted to be able to show beyond the date, the hour and the minute, because I need these data for what at the time of listing.

And how could I do this listing by putting the current ones in the user's view, that is, in evidence?

Here I will show you what the search I do in the bank to show the occurrences is:

The ActionResult that scans the table and shows the data (That for now, I show the names, but I want to show the names and dates, as described above):

public ActionResult Inicio()
{
    List<Ocorrencia> resultado = db.Ocorrencias.Include(o => o.Aluno).ToList();
    return View(resultado);
}

So basically I just look for the names, and with that the new occurrences are getting underneath the old ones, and that's not what I need. I need the new ones, listed by date, to stay up, in evidence .... But how do I do that?

    
asked by anonymous 12.08.2014 / 16:47

1 answer

5

If I understand correctly, you want to list all your occurrences sorted by date. If so, just query in the controller, sort by date:

public ActionResult Inicio()
{
    List<Ocorrencia> resultado = db.Ocorrencias.Include(o => o.Aluno).OrderBy(c => c.DataAOrdenar).ToList();
    return View(resultado);
}

To display the date in dd-MM-yyyy HH:mm format, in the view you do:

@Html.TextBoxFor(model => model.DataAOrdenar, "{0:dd/MM/yyyy HH:mm}")
    
12.08.2014 / 17:11