score:9
you shouldn't to try order the date as string;
var res = objui.where(x => x.lastlogin != null)
.groupby(x => x.lastlogin.value.date)
.orderbydescending(x => x.key)
.select(x => new { lastlogin = string.format("{0:mm/dd/yyyy}", x.key) })
.tolist();
score:7
you're ordering by your string representation which starts with the month.
it looks like you're actually only interested in distinct dates though - grouping and then discarding everything other than the key is equivalent to just projecting and then taking distinct data. i'd also suggest avoiding an anonymous type unless you really need it - an anonymous type with only a single property is usually a bad idea.
finally, if you're formatting a single value - certainly a datetime
value - it's simpler to just call the tostring
method. in the code below i've explicitly specified the invariant culture too - otherwise you may find an unexpected calendar system is used...
so i'd write:
var res = objui.where(x => x.lastlogin != null)
.select(x => x.lastlogin)
.distinct()
.orderbydescending(x => x)
.select(x => x.tostring("mm/dd/yyyy", cultureinfo.invariantculture))
.tolist();
Source: stackoverflow.com
Related Query
- Groupby multiple date properties by month and year in LINQ
- I wants to date month and year add 2 month later in linq
- orderByDescending date, month and year
- Group by year and month with given date range using Lambda or LINQ Query
- How to get Date Month and Year Number using dataSet.Tables query
- LINQ how to Group data by date day and month and year
- LINQ: Group by month and year within a datetime field
- linq order by Month Name and Year (MMM yyyy string)
- How to add Month in date time and Compare with another date time in Linq?
- LINQ - Group by Year and Month
- Dictionary of dates and values, finding value of max date per year in LINQ
- C# LINQ create month and year list
- how can i wirte linq to compair the year and month f
- Group items by month and by date
- Get Month name and year from list
- Sorting Linq Result by Year and Month
- How to group an SQL date column stored as int as Year Month using LINQ
- Orderby month and year using linq
- Group by year descending, order by month and total on another column Linq query
- Counting active listings by month and year
- Month and Year drop down list for ASP.NET mvc
- get number of transactions within a certain month and year
- Group DateTime by year and month then order it
- Turning List<DateTime> into Lists that have them separated per same month and year
- Search for month or year in a date using Linq based on condition
- Fetch month and Year Inside a List using Linq
- Using LINQ to transform Date into a WeekDay and Week of Month
- check a List of values in db and retrieve items that fall under a Date Time Month Property
- LINQ compare values for the same year , different month and doing a count if value has changed
- linq to sql, select by dates that match to month and year from dates array
More Query from same tag
- Return Rows with Unique and Duplicate values from dataTable using LINQ
- Search DataTable with values from another table
- Insert new records using Linq
- Get the number from list using LINQ with specific conditions
- how to retrieve data between two dates in linq
- Find and change the value of first element in list that meets a requirement, do something else if not found
- How to map extra additional property on Entity database call
- In Controller, return records with [verified_date] older than 3 months from current date?
- How can I specify a "where" condition in my query?
- Query which returns results only if all (non-primitive) values from a compared enumerable are contained in the target enumerable
- Dicing entities by date in entity framework
- Rowspan in the view (mvc4)
- Dynamic LINQ. No property or field 'FieldName' exists in type 'ClassName'
- isolation level in linq to sql , DataContext
- C# Lambda? In list of class find highest property (int) where property (character) = 1
- LINQ Except/Distinct based on few columns only, to not add duplicates
- Take a group of numbers put them in 3 new groups evenly
- C# Value from another List linked to value
- Getting some input from user and insert multiple table with Entity Framework
- C# MongoDB, LINQ unable to match by Id
- Cannot implicitly convert type 'bool' to 'system.threading.tasks.task bool'
- How to convert datatable to corresponding "named" and "typed" IEnumerable for Intellisense
- Update Enumerable<T> based on the Selected row and save into db
- Linq query to join against list in a struct
- Filter a list based on multiple criteria and multiple values (unknown number of values)
- Read Foursquare Json Response with JSON.NET
- Using Linq to find instances that contain a set of objects
- select from list which has same code
- Merge two List<object> into one List in Linq
- Explanation of how this lambda expression in plain English?