Given the list of ranges datetime (start and end time), how can I sort them by duration (eg.largest to smallest duration)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming each object in the list is of the type DateTime then you can use the Ticks property to sort them.
http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx
If they are ranges, you can subtract the Ticks of the start time from the Ticks of the end time and use the resulting value to sort.
For example:
This will give you a number of “Ticks” that represent the length of time in your range, the smaller the number, the shorter the duration.
Repeat this for each range, and then you can sort the results.