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 7733007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:52:31+00:00 2026-06-01T06:52:31+00:00

I’m writing an application where users enter some details into an SQLite Database. I

  • 0

I’m writing an application where users enter some details into an SQLite Database. I need to write code whereby the last 31 days of stored data in the database is outputted.

The code to save the date string is:
currentDateString = DateFormat.getDateInstance().format(new Date());

This gives the date in the format (for todays date) as 30 Mar 2012.

Is there anyway to change this data format into DD/MM/YYYY? (30/03/2012)

This string is saved into the SQL Database as follows:

ContentValues dbcv = new ContentValues();
dbcv.put(KEY_DATE, date);

(currentDateTime String = Date in previous class)

I wish to output every row of the database that comes within the last 31 days.

How can I do this?

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-01T06:52:32+00:00Added an answer on June 1, 2026 at 6:52 am

    First of all, you are doing two questions instead on just one, I will try to give you an answer to both.

    1. To change the date format in java take a look at the documentation for the SimpleDateFormat, you can pass a pattern to the constructor of that class to make it format your dates the way you really want. In your specific case the pattern you are looking for is dd/MM/yyyy
    2. If you are storing dates in your database as strings you lose some of the benefits that storing dates as they are have. For example, your second question will be easily performed if you were storing dates instead of strings in your tables since the only thing you need to achieve what you want is to do a select operation to your table using the date functions provided by SQLLite. Take a look a this webpage as it will give you an idea of what you can do with those functions: SQLLite Date Functions

    Note: Of course, if you still want to store them as strings the only solution you will have is read all the records, parse all the strings back to dates and use the java.util.Calendar class to check which record is older than 31 days and which one is not. I’d rather do the SQL query instead of that as it has too much better performance (specially on a mobile device).

    EDIT:

    SQLLite and Android are not specifically my strengths, I did a small research and I found several posts in which people were actually storing them as strings as you initially started to do. If SQLLite on Android doesn’t support storing dates as they are (as other databases do) then maybe the best option in your scenario is using a long value as the date. Look at the Date definition class, it has a method getTime that returns the date value as long value, you can use that value later to create a new instance of a date (using its constructor).

    To format that date (the Date object, of course) in something readable by the user, DateFormat (or any of its implementations) is still the answer.

    To do the query you want to do having dates stored as longs I suggest you to take a look to the DateUtils class from the Apache Commons Lang library. In that class you will find several functions that work on dates, so, before creating the query you need to fetch the rows in last 31 dates, you could use something like:

    Date now = new Date();
    Date before = DateUtils.addDays(now, -31);
    long beforeAsLong = before.getTime();
    String query = "select * from TABLE_NAME where DATE_FIELD >= " + beforeAsLong;
    

    Hope this helps.

    • 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 ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ 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.