Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:44:20+00:00 2026-06-17T05:44:20+00:00

Mac OS-X Android Eclipse with ADT SQLite I’m new to creating Android Apps and

  • 0

Mac OS-X

Android

Eclipse with ADT

SQLite

I’m new to creating Android Apps and Ive researched this heavily but I’m getting nowhere. I need to query my SQLite database to return all the rows between 2 dates. What I have learnt from my research so far is that there is no DateTime column in Androids SQLite database and I have to save it as a text column. But I think the problem lies with trying to compare Strings but I can’t figure out a way around it. Here is my code :

DB = currentContext.openOrCreateDatabase(DBName, 0, null);
DB.execSQL("CREATE TABLE IF NOT EXISTS " + tableName + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, Date VARCHAR(40), Hours INT(3));");

I am not getting any errors but I am not returning any results from my RawQuery. Here is my code:

Cursor c = newDB.rawQuery("select ID, Date, Hours from " + tableName + " where Date BETWEEN '" + date1 + " 00:00:00' AND '" + date2 + " 99:99:99'", null);

if (c != null ) {
  Log.d(TAG, "date1: "+date1);
  Log.d(TAG, "date2: "+date2);
  if  (c.moveToFirst()) {
     do {
        int id = c.getInt(c.getColumnIndex("ID"));
        String date1 = c.getString(c.getColumnIndex("Date"));
        int hours1 = c.getInt(c.getColumnIndex("Hours"));
        results.add(+ id + "    Date: " + date1 + "    Hours: " + hours1);
     }
         while (c.moveToNext());
      }
}

I have also tried the following statement but they do not yield results either:

Cursor c = newDB.rawQuery("select ID, Date, Hours from " + tableName + " where Date BETWEEN " + Date(date1) + " AND " + Date(date2) + "", null);

I got this statement from other StackOverflow answers but I cannot find any documentation on the date() method. Im not sure whether it is obsolete now but I get error saying “Date(String) method is undefined for the type (classname)” and I have tried importing some JAVA Libraries.

Does anyone know the correct way to create a rawData() query that will get the rows between selected dates??

Further info, these are my INSERT statements and the date format that goes into the database:

newDB.execSQL("INSERT INTO " + tableName + " (Date, Hours) Values ('" + ph_date + "'," + hours + ");");
String date1 = "12/1/13"
String date2 = "25/1/13"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:44:22+00:00Added an answer on June 17, 2026 at 5:44 am

    Ok, so I could not get string dates to work, so I had to convert String Dates to Calendar Dates to Unix Time before adding them to the SQLite database and convert them back (Unix Time to Calendar Dates to String) when displaying them. Unix Time allows calculations (order by, sort ascending, between etc) done on the date columns and it is the best method to use after long hours of trial and error. Here is the code I ended up using:

    Cursor c = newDB.rawQuery("select ID, Date, Hours from " + tableName + " where Date BETWEEN '" + startDateQueryDate + "' AND '" + endDateQueryDate + "' ORDER BY Date ASC", null);
    
                if (c != null ) {
                    if  (c.moveToFirst()) {
                        do {
                            int tempId = c.getInt(c.getColumnIndex("ID"));
                            long tempUnixTime = c.getLong(c.getColumnIndex("Date"));
    
                            //convert tempUnixTime to Date
                            java.util.Date startDateDate = new java.util.Date(tempUnixTime);
    
                            //create SimpleDateFormat formatter
                            SimpleDateFormat formatter1;
                            formatter1 = new SimpleDateFormat("dd/MM/yyyy", Locale.UK);
    
                            //convert Date to SimpleDateFormat and convert to String
                            String tempStringStartDate = formatter1.format(startDateDate);
    
                            int tempHours = c.getInt(c.getColumnIndex("Hours"));
                            results.add(+ tempId + "    Date: " + tempStringStartDate + "    Hours: " + tempHours);
                        }while (c.moveToNext());
                    }
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[2010-12-17 07:37:12 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Unable to read /Users/macuser/android-sdk-mac/AndroidManifest.xml: java.io.FileNotFoundException: /Users/macuser/android-sdk-mac/AndroidManifest.xml (No such file or
I am using Eclipse Juno on Mac OS 10.7.4 and Android ADT. Some times
I'm using Eclipse on mac for developing android apps. When I run the application
I want to develop Android apps on the Mac, but the information on http://developer.android.com/sdk/index.html
Mac OS-X ECLIPSE with ADT ANDROID ................ Problem: When I pick the time, say
Using Mac OS X 10.6.2, Eclipse SDK 3.5.2. I installed the Android plugin, following
I am a new Mac OS user and I transfered my Android project to
Trying to generate JavaDocs for the Android lint-cli project on Mac 10.7 Keep getting
I am new to Android development. I have both Windows 7 and Mac OS
I've just set up my first Android development environment consisting of Eclipse 3.5 Mac

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.