Do dates search using MVC5

Asked

Viewed 24 times

-1

Good afternoon, guys, okay? I hope so. I’m having doubts about ordering the database data in ascending order of dates. var result = from r in context.name Where r.numero == 2 orderby r.datacadastro select r;

But do not return with ordered dates. it orders by day. for example: 01/09/2020 02/10/2019 03/02/2014 07/09/2020... I believe it has something to do with Sql Server being registered with American dates and VS is returning the dates in pt, or vice versa. How do I fix it?

  • Submit a [MCVE]

  • In your database, are these dates registered in a Date/Datetime field? Because from what you described, it is as if he is returning the dates in "alphabetical/numerical order", disregarding the ordering by date and rather considering as a string.

1 answer

1

Good afternoon, Marcio!

I think the example below will help you:

var resultado = context.nome.OrderByDescending(c => c.datacadastro).ToList();

Something to that effect.

Hugs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.