Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Confused sorting on SQLLite dates

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-17-2008, 07:25 PM
Junior Member
 
Join Date: Aug 2008
Location: Guildford, UK
Posts: 28
Default Confused sorting on SQLLite dates

Hi,

I'm using the sample program (sql.sbp) to learn about SQLLite databases.
I'm getting on OK except I cannot get dates to order properly. For example, if I enter the following into the SQL query text box "SELECT * FROM orders ORDER BY OrderDate" and execute it the data is returned with the OrderDate sorted like a string, NOT a date.

How do I store dates and sort on them?

Thanks

Mike White
Reply With Quote
  #2 (permalink)  
Old 08-18-2008, 12:40 AM
Basic4ppc Veteran
 
Join Date: Jan 2008
Posts: 215
Default SQLite date/time

Have you tried converting the date from a string to date format? The SQLite web site gives some examples: SQLite Query Language: Date And Time Functions

This works for me in the demo: SELECT * FROM orders ORDER BY date(orderdate)

I hope that helps.
Reply With Quote
  #3 (permalink)  
Old 08-18-2008, 04:21 PM
Junior Member
 
Join Date: Aug 2008
Location: Guildford, UK
Posts: 28
Default

Thank you! That works very well.

Now though I'm confused by how to construct my insert/update statements for timestamp fields (which is what the OrderDate field is).

If I insert like so '1999-07-03 12:15:13' the data will sory by date but ignores the time field. It also returns as 1999-07-03 where I would prefer 07-03-1997 for easy use in Dateparse etc.

I seem to be making a mountain out of what must really be very simple!

Thanks

Mike White
Reply With Quote
  #4 (permalink)  
Old 08-18-2008, 05:25 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Try:
Code:
SELECT * FROM orders ORDER BY <b>datetime</b>(orderdate)
You can also change Basic4ppc date and time format:
Code:
Sub App_Start
    DateFormat(
"yyyy-mm-dd")
    TimeFormat(
"hh:mm:ss")
    t = 
"1999-07-03 12:15:13"
    dateTicks = DateParse(SubString(t,
0,10))
    timeTicks = TimeParse(SubString(t,
11,8))
    
Msgbox("Date: " & Date(dateTicks) & crlf & _ 
        
"Time: " & Time(timeTicks))
End Sub
Reply With Quote
  #5 (permalink)  
Old 08-18-2008, 08:16 PM
Junior Member
 
Join Date: Aug 2008
Location: Guildford, UK
Posts: 28
Default

Thanks,

I'm on my way again. I also thought about just storing the number of ticks in a field and then decoding that via Date and time.

Mike
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
sqlite sorting dennishea Questions (Windows Mobile) 3 09-12-2008 07:26 PM
help with dates adbftrainer Questions (Windows Mobile) 3 08-31-2008 05:56 PM
Sorting objects in the IDE - a further tweak? agraham Basic4ppc Wishlist 2 12-28-2007 05:05 PM
Binary Files- Love'm and sometimes confused XerVision Questions (Windows Mobile) 2 06-10-2007 07:55 PM
Sql sorting problem... belotrei Questions (Windows Mobile) 4 06-05-2007 11:26 AM


All times are GMT. The time now is 10:18 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0