Sorting based on timestamps