Date sorting logic in course form