c# - Order List by Date and Time (in string format) -


probably i'm asking quite simple don't seem getting 1 out. have list of elements containing date field , time field. date field regular datetime , time field string. time formatted hh:mm , ranges in 24h.

ordering list date simple doing list.orderby(e => e.date), don't seem able later order time order of records according date , time.

i tried out it's big mistake!

    list = list.orderby(e => e.estimateddate).orderby(e => new timespan(int.parse(e.estimatedtime.substring(0,e.estimatedtime.lastindexof(":"))),int.parse(e.estimatedtime.substring(e.estimatedtime.lastindexof(":")+1)),0).totalminutes); 

i hope can me out one.

you want orderby(...).thenby(...); , - not if time in hh:mm you don't have parse it - can sort alphabetically, i.e.

list = list.orderby(e => e.estimateddate).thenby(e => e.estimatedtime).tolist(); 

or via linq:

list = (from e in list         orderby e.estimateddate, e.estimatedtime         select e).tolist(); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -