This is more of a follow-up to my post yesterday on how to convert dates from SharePoint to javascript. Today I’ll show you how to pull a list of dates from SharePoint (as well as other fields), push them into an array, and then sort that array by date.
Problem: Pull a list of reservations from a SharePoint and order them chronologically. There are three fields, firstName, lastName, and startTime. We want to pull all three fields, and then output those fields into an unordered list. As an added trick, we have several reservation lists we need to pull from (Elementary School, Middle School, and High School). So all reservations need to be pulled, and then sorted chronologically.
Solution 1: Just modify your CAML query to OrderBy the startTime field. Well, this works fine. But when pulling from multiple lists (using SPServices), the results will essentially be “grouped” by list.
Solution 2: Push all results to a javascript array, then sort the array. The problem here is that SharePoint’s date/time field isn’t very javascript-y. So sorting won’t work.
Solution 3: Use the convertSPDate() function mentioned in yesterday’s post on converting dates from SharePoint to javascript, then follow solution 2!
Here’s the code (commented with explanations):

