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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:10:30+00:00 2026-05-23T14:10:30+00:00

I have a string stored in a database (example: Sat Jul 09 14:20:31 EDT

  • 0

I have a string stored in a database (example: Sat Jul 09 14:20:31 EDT 2011)

This is stored as string (I am aware of SQLs date capabilities, but I’m not exploring that at this point).

I want to pull this strong and compare it with the current time using the Date.compare function


Date currentDate = new Date(); // the new current time value
mCursor.getString(mCursor.getColumnIndex(TIMECOLUMN)
//the old stored time value, pulled from the SQL database

From the database I have a string value already formatted as a proper date. But I don’t have an obvious function to compare this to my current date as a date object.

I need to know if one is greater than, less than, or equal to, the other. The Date compare function will allow this, but the object needs to be a date object.

I have tried SimpleDateFormat seeded with the string’s date format, but I get a parse exception “unparsable date”, perhaps because it is already formatted?


Date currentDate = new Date();
SimpleDateFormat dateTest = new SimpleDateFormat("E M d HH:mm:ss z y");
if(currentDate.compareTo(dateTest.parse((mCursor.getString(mCursor.getColumnIndex(TIMECOLUMN))))) > 0)

returns java.text.ParseException: Unparseable date: Sat Jul 09 14:20:31 EDT 2011

I suspect my SimpleDateFormat seed is incorrect. Insight Appreciated

  • 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-05-23T14:10:31+00:00Added an answer on May 23, 2026 at 2:10 pm

    I believe you just need to change the “M” to “MMM” in your format string:

    SimpleDateFormat format = new SimpleDateFormat("E MMM d HH:mm:ss z y");
    

    “M” is a potentially-single-digit value, e.g. 1, 10 etc. “MMM” is a short month name (e.g. “Jul”, “Sep”).

    However, you should probably also specify the locale of the date format. I’d also strongly encourage you to break your currently huge statement into several bits to make it easier to understand and debug:

    int timeColumn = mCursor.getColumnIndex(TIMECOLUMN);
    String dbDateText = mCursor.getString(timeColumn);
    Date dbDate = format.parse(dbDateText);
    
    if (currentDate.compareTo(dbDate) > 0) {
    }
    

    I’d also encourage you to use Joda Time for date/time-related work, and to avoid storing date/time data as text in the database 🙂

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

Sidebar

Related Questions

I have this string stored in a variable: IN=bla@some.com;john@home.com Now I would like to
I have an email body stored as a string in a database, something like
Ok so I have a database row with a specified string in for example
I have 100000 Ids to store into our DataBase. Id is in string format.each
i have string stored in python variables, and i am outputting a html that
In my applications web.config file I have a connection string stored. I encrypted it
I have a variable, emailBody, which is set to a string stored in a
ok so my issue is i have the string '\222\222\223\225' which is stored as
i have an account number that is stored in as a query string. How
I have a task of parsing a simple XML-formatted string in a MySQL stored

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.