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

  • SEARCH
  • Home
  • 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 7744581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:48:07+00:00 2026-06-01T09:48:07+00:00

I’ve added 3 strings of data into a SQL database in android. A fourth

  • 0

I’ve added 3 strings of data into a SQL database in android. A fourth string makes up the database, however it is a date:

SimpleDateFormat outputDate = new SimpleDateFormat(yyyy-MM-dd)

Date outputDate = new Date();

When the user enters information to the database, the adding method for the database creates the date, which is added to the database.

My question is, how can I use these imported dates to create a method whereby only the rows in the database that were added on in the last 31 days?

A SELECT method comes to mind through research, but I don’t know how to implement it?

Thanks

  • 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-01T09:48:08+00:00Added an answer on June 1, 2026 at 9:48 am

    As long as you ask about Android I assume that the database you use is SQLite. SQLite does not have datatype for date. Thus you have couple of options: store the date in string (like you did) or store the timestamp of the date.

    I seriously recommend you to use the second option as it is going to convert your dates in integers and it will be even easier to handle.

    Thus when you want to select only events in the last 31 days you can do:

    SQLiteDatabase database = helper.getWriteableDatabase();
    final long millisIn31Days = 31 * 24 * 60 * 60 * 1000; 
    String where = "<your-date-column> >= ?"
    String [] whereArgs = { String.valueOf(new Date().getTime() - millisIn31Days) };
    Cursor cursor =
        database.query("<TABLE_NAME>", null, where, whereArgs, null, null, null);
    

    Note that here I write in angular brackets all the values you should actually fill in with the correct constants.

    If you, however, want to stick to the string solution, you can still go with string comparison, as long as you specify the date format in correct manner (yours seems to be like that). In the string solution you will need to calculate the date of 31 days ago. You can use the Calendar‘s class auxiliary methods to achieve that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.