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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:42:37+00:00 2026-06-07T16:42:37+00:00

I am using Javascript engine to compare values. Values can be double or date.

  • 0

I am using Javascript engine to compare values. Values can be double or date. (strings)

ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
// Date value is populated dynamically here
engine.eval("dateValue = " + "01/02/2012");
// The condition is populated dynamically here
if ((Boolean) engine.eval("dateValue <=" + "12/31/2012")) { 
  System.out.println("TRUE");
} else {
    System.out.println("FALSE");
}

The above code works fine with double values, but gives wrong results with dates. For the above example it should display TRUE, but it displays FALSE. Please help.

  • 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-07T16:42:38+00:00Added an answer on June 7, 2026 at 4:42 pm

    You should do something like:

    engine.eval("var dateValue = " + "new Date(2012, 02, 01);");
    ...
    if ((Boolean) "dateValue <=" + " new Date(2012, 12, 31);")
    

    In your script 12/31/2012 will be interpreted as a mathematical expression.

    another possibility for the test you wanna do is something like:

    engine.eval("var test = dateValue <=" + " new Date(2012, 12, 31);")
    Object myBoolean = engine.get("test");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using javascript, How can I convert a human time string like Wed Jun 20
Using JavaScript, how do I create an HTML table that can "accept" numeric matrix
I just started using a javascript engine from Microsoft(of IE9?) for developing both desktop
I'm using javascript and THREE.js 3d engine, and I want to do a fog
When I discovered that Node.js was built using the V8 JavaScript engine , I
Possible Duplicate: javascript compare strings without being case sensitive. I am having two fields.
I am using Apache Httpclient and I need to use a Javascript engine to
I want to load a JavaScript file using Jint, but I can't seem to
I'm using the javax.script.* package of the JDK. Specifically, I'm using the JavaScript engine,
I'm writing a simple JavaScript 3D engine from scratch using Canvas and box like

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.