Answered by:
Order of data has changed after sorting date values in data.

Question
-
Hi,
I have a custom class with some fields (Subject and StartTime) and custom comparer for sorting the time values and stored data in ArrayList collection.
Sample Data in collection:
Subject = App1 and StartTime = 25/11/2019
Subject = App1 and StartTime = 26/11/2019
Subject = App1 and StartTime = 27/11/2019
Subject = App1 and StartTime = 28/11/2019
Subject = App1 and StartTime = 29/11/2019
Subject = App1 and StartTime = 30/11/2019
Subject = App1 and StartTime = 01/12/2019
Subject = App2 and StartTime = 25/11/2019
Subject = App2 and StartTime = 26/11/2019
Subject = App2 and StartTime = 27/11/2019
Subject = App2 and StartTime = 28/11/2019
Subject = App2 and StartTime = 29/11/2019
Subject = App2 and StartTime = 30/11/2019
Subject = App2 and StartTime = 01/12/2019
Subject = App3 and StartTime = 25/11/2019
Subject = App3 and StartTime = 26/11/2019
Subject = App3 and StartTime = 27/11/2019
Subject = App3 and StartTime = 28/11/2019
Subject = App3 and StartTime = 29/11/2019
Subject = App3 and StartTime = 30/11/2019
Subject = App3 and StartTime = 01/12/2019
Problem:
FYI : Date values in collection are from 25/11/2019 to 01/12/2019 (including Saturday and Sunday).
After sorting the date values, times are sorted properly but objects or records order is changed.
Expected result:
Subject = App1 and StartTime = 25/11/2019
Subject = App2 and StartTime = 25/11/2019
Subject = App3 and StartTime = 25/11/2019
Subject = App1 and StartTime = 26/11/2019
Subject = App2 and StartTime = 26/11/2019
Subject = App3 and StartTime = 26/11/2019
Observed result:
Subject = App1 and StartTime = 25/11/2019
Subject = App3 and StartTime = 25/11/2019
Subject = App2 and StartTime = 25/11/2019
Subject = App1 and StartTime = 26/11/2019
Subject = App3 and StartTime = 26/11/2019
Subject = App2 and StartTime = 26/11/2019
//
//
Subject = App3 and StartTime = 28/11/2019
Subject = App2 and StartTime = 28/11/2019
Subject = App1 and StartTime = 28/11/2019
Note: This problem occurs only when collection has Saturday and Sunday values (30/11/2019 and 01/12/2019).
If don’t have that 2 dates in collection, the records are in correct order as expected result after sorting.
Here I have attached sample demo & screenshots for your reference.
Please guide me to have sorted objects in correct order as expected result (with Sat and Sun dates) and let me know if I did anything wrong.
Thanks,
- Edited by Piruthiv Wednesday, December 18, 2019 7:09 AM
Wednesday, December 18, 2019 7:07 AM
Answers
-
Which programming language do you use? Instead of a zip file with demo you should only show the source code of your comparison function. As far as I can conclude from your explanation, the sort of date is correct. You must sort a second "column" in order to sort the Subjects too.
Check your programming language and ask in an appropriate forum: https://social.msdn.microsoft.com/Forums/en-US/home?category=vslanguages
- Proposed as answer by Dave PatrickMVP Wednesday, December 18, 2019 1:18 PM
- Marked as answer by Richard MuellerMVP Thursday, December 26, 2019 12:45 AM
Wednesday, December 18, 2019 8:04 AM
All replies
-
If the question is on .NET (C# language), please post it in below forum:
https://social.msdn.microsoft.com/Forums/en-US/home?forum=csharpgeneral
If the response helped, do "Mark as answer" and upvote it
- VaibhavWednesday, December 18, 2019 7:21 AM -
Which programming language do you use? Instead of a zip file with demo you should only show the source code of your comparison function. As far as I can conclude from your explanation, the sort of date is correct. You must sort a second "column" in order to sort the Subjects too.
Check your programming language and ask in an appropriate forum: https://social.msdn.microsoft.com/Forums/en-US/home?category=vslanguages
- Proposed as answer by Dave PatrickMVP Wednesday, December 18, 2019 1:18 PM
- Marked as answer by Richard MuellerMVP Thursday, December 26, 2019 12:45 AM
Wednesday, December 18, 2019 8:04 AM -
Thanks, I have posted my query in respective forum.Wednesday, December 18, 2019 8:45 AM