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!

5
  • 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? Commented Jan 31, 2013 at 16:16
  • I'm fairly knew to this level of javascript - what would be the normal format to work in ? Commented Jan 31, 2013 at 16:29
  • Firstly, you need to change the field type in the SQL table to DateTime. Then, look here for an example of how to format the date object in javascript so you can make it a suitable value to be stored. Commented Jan 31, 2013 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. Commented Jan 31, 2013 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. Commented Jan 31, 2013 at 17:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.