0

I'm in the process of building a phonegap app that uses websql.

Within my phonegap DB I have recordings, the table looks like this

ID, ref, startdate, enddate .... etc

On one of my apps pages I get all these records and append them to a listview (I'm using JQM).

I want to order these by the start date, but its not as simple as just using a SQL ORDER BY as the dates are stored in the Javascript date object format, for example - Tue Jan 29 15:59:02 GMT+0000(GMT). I want to order these by decending date order before I append them to my list.

Could someone point me in the right direction of how to achieve this with javascript?

Thanks in advance!

Jimothey
  • 2,414
  • 9
  • 41
  • 66
  • It would make a lot more sense to store the dates in a datetime format. I can't see any benefit of storing them as strings. Can you not just modify the insert procedure? – Reinstate Monica Cellio Jan 31 '13 at 16:16
  • I'm fairly knew to this level of javascript - what would be the normal format to work in ? – Jimothey Jan 31 '13 at 16:29
  • Firstly, you need to change the field type in the SQL table to DateTime. Then, look [here](http://stackoverflow.com/questions/6702705/how-to-convert-javascript-datetime-to-c-sharp-datetime) for an example of how to format the date object in javascript so you can make it a suitable value to be stored. – Reinstate Monica Cellio Jan 31 '13 at 16:35
  • Thanks I'll look into that - I've been using that format as thats exactly what iOS datepickers leave you with as the value of any datetime fields, a quick date() converts them into js friendly dates so it avoiding any funky date formatting. – Jimothey Jan 31 '13 at 16:57
  • Right that makes sense, but you should be able to pass something like 'mm/dd/yyyy' into `Date()` to create a date object as well. Really it should be down to what you use the most in the project, but I usually start at the bottom (database) and work up from there. – Reinstate Monica Cellio Jan 31 '13 at 17:16

0 Answers0