Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hii,

I have a customer list which shows like
A-Customer ----- 10:00 AM ----- Branch1
B-Customer ----- 1:00 PM ------ Branch1
c-Customer ----- 5:00 PM ------ Branch1
D-Customer ----- 7:00 PM ------ Branch1
E-Customer ----- 12:00 PM ------ Branch1

here my problem is how to set 12:00 PM first in PM list and then all PM list will be in show in ascending order.

What I have tried:

@foreach (var item in Model.OrderBy(x => x.AMPM).ThenBy(x => x.hour).ThenBy(x => x.minute))
{
<tr @Html.Raw(Model.IndexOf(item) == 0 ? "style=\"background-color:lightblue;\"" : "")>

@item.FirstName @item.BookingTime @item.EmployeeName }
Posted
Updated 4-Apr-18 0:31am
Comments
F-ES Sitecore 4-Apr-18 6:22am    
Without knowing the data structure and types involved it is impossible to say. If you are storing the data correctly in the correct date types then it could be a case of saying where the time\hour is >= 12 then order by that date. If you are storing your dates as text then it all gets much more complicated, which is why you shouldn't.

1 solution

Make your life easy:   reconfigure your data into 24hour time - then sorting by time is very easy: 0:00 through 23:59.

If that is impossible, then you need to have a multiple step set of conditionals in your sort where you look for 12:nn and set its position separately compared to all of the other values.

something like (oversimplified time, psuedo-code):
// Separate out morning times
if( (hour<12 and daytime='AM') or (hour==12 and daytime='PM) )
  SortByHour(); //  since your 12 is at the end 
                //  of this time block
else
  HandleTheOthers();
But I cannot overemphasize that converting to 24 hour time is the way to go!
 
Share this answer
 
v2
Comments
Member 13254700 4-Apr-18 6:37am    
Now it solved. I set 12:00 to 00:00 in data short list. So now 12:00PM is smaller then 1:00 PM so now its working well.
Thanks....
Maciej Los 4-Apr-18 6:40am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900