This is a migrated thread and some comments may be shown as answers.

Sorting by a DateTime Field Ignoring The Year

2 Answers 438 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alexandre
Top achievements
Rank 2
Alexandre asked on 14 Nov 2012, 01:17 PM
Hi,

How can i use a orderby clause using a DateTime field ignoring the year?

Is that possible?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Tachev
Telerik team
answered on 16 Nov 2012, 04:40 PM
Hi Alexandre,

In order to use the OrderBy clause on a DateTime field ignoring the year I suggest you to base your query on the following code snippet which is retrieving data from the Orders table of the Northwind database.         

...
using (YourContextName db = new YourContextName())
{
    var orderByDateTimeWithoutYear = db.Orders
        .Where(x => x.OrderDate.HasValue)
        .OrderBy(x => x.OrderDate.Value.Month)
        .ThenBy(x => x.OrderDate.Value.Day);
      ...
}
...
If you want to become more familiar with the LINQ capabilities of OpenAccess ORM you can download our SDK and look at our Linq 101 sample.

I hope this helps.


Regards,
Dimitar Tachev
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
0
Alexandre
Top achievements
Rank 2
answered on 21 Nov 2012, 12:31 PM
Thanks Dimitar!

Works perfectly!
Tags
LINQ (LINQ specific questions)
Asked by
Alexandre
Top achievements
Rank 2
Answers by
Dimitar Tachev
Telerik team
Alexandre
Top achievements
Rank 2
Share this question
or